Module: Syde::Vault::Storage

Defined in:
lib/syde/storage.rb

Constant Summary collapse

DefaultStorageFile =
File.expand_path("~/.syde/storage_file.vault")

Class Method Summary collapse

Class Method Details

.file(mode = "r", &block) ⇒ Object



32
33
34
# File 'lib/syde/storage.rb', line 32

def self.file(mode = "r", &block)
	File.open(DefaultStorageFile, mode, &block)
end

.read(content) ⇒ Object



18
19
20
# File 'lib/syde/storage.rb', line 18

def self.read(content)
	file { |f| f.read }
end

.valid_format?(data) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
# File 'lib/syde/storage.rb', line 7

def self.valid_format?(data)
  data.is_a?(Hash) &&
	data.keys.include?(:encrypted) &&
	data.keys.include?(:plaintext) &&
	data[:plaintext].keys.include?(:iv) &&
	data[:plaintext].keys.include?(:secret_key_hash) &&
	data[:encrypted].keys.include?(:secret_key) &&
	data[:encrypted].keys.include?(:contents) &&
	data[:encrypted][:contents].is_a?(String)
end

.write(content, file = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/syde/storage.rb', line 22

def self.write(content, file = nil)
  if file
    File.open(file, "w") do |f|
      f << content
    end
   else
     file("w") { |f| f << content }
    end
end