Class: EncryptedKeystore

Inherits:
Object
  • Object
show all
Defined in:
lib/encrypted_keystore.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file: nil, out: nil, key: nil, iv: nil) ⇒ EncryptedKeystore

Returns a new instance of EncryptedKeystore.



21
22
23
24
25
26
# File 'lib/encrypted_keystore.rb', line 21

def initialize(file: nil, out: nil, key: nil, iv: nil)
  @file = file
  @out = out
  @key = key
  @iv = iv
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/encrypted_keystore.rb', line 7

def file
  @file
end

#ivObject

Returns the value of attribute iv.



7
8
9
# File 'lib/encrypted_keystore.rb', line 7

def iv
  @iv
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/encrypted_keystore.rb', line 7

def key
  @key
end

#outObject

Returns the value of attribute out.



7
8
9
# File 'lib/encrypted_keystore.rb', line 7

def out
  @out
end

Class Method Details

.decrypt(file: nil, out: nil, key: nil, iv: nil) ⇒ Object



16
17
18
19
# File 'lib/encrypted_keystore.rb', line 16

def self.decrypt(file: nil, out: nil, key: nil, iv: nil)
  enc = new(file: file, out: out, key: key, iv: iv)
  enc.decrypt
end

.encrypt(file: nil, out: nil) ⇒ Object



9
10
11
12
13
14
# File 'lib/encrypted_keystore.rb', line 9

def self.encrypt(file: nil, out: nil)
  enc = new(file: file, out: out)
  enc.encrypt

  { key: enc.key, iv: enc.iv }
end

Instance Method Details

#decryptObject



28
29
30
31
32
33
34
# File 'lib/encrypted_keystore.rb', line 28

def decrypt
  validate

  write(dec_cipher)
  FileUtils.chmod(0o0600, @out)
  @out
end

#encryptObject



36
37
38
39
40
# File 'lib/encrypted_keystore.rb', line 36

def encrypt
  validate(enc: true)

  write(enc_cipher)
end