Class: Key

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_) ⇒ Key

Returns a new instance of Key.



9
10
11
12
# File 'lib/key.rb', line 9

def initialize(hash_)
	@key_id, @encrypted, @type_name, @security_level = hash_.values_at("keyID", "encrypted", "typeName", "securityLevel")
	@type = types[@type_name] || Password
end

Instance Attribute Details

#encryptedObject (readonly)

Returns the value of attribute encrypted.



2
3
4
# File 'lib/key.rb', line 2

def encrypted
  @encrypted
end

#key_idObject (readonly)

Returns the value of attribute key_id.



2
3
4
# File 'lib/key.rb', line 2

def key_id
  @key_id
end

Instance Method Details

#decrypt(encryption_key) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/key.rb', line 14

def decrypt(encryption_key)
	encryption_key_item = encryption_key.get(@key_id) || encryption_key.get(@security_level)
	decrypted_master_key = encryption_key_item.decrypted_master_key
	return unless decrypted_master_key
	decrypted_content = JSON.parse Decrypt.decrypt_ssl(decrypted_master_key, @encrypted)		
	@type.new decrypted_content
end

#typesObject



4
5
6
7
# File 'lib/key.rb', line 4

def types
	{"webforms.WebForm" => WebForm, 
	 "passwords.Password" => Password}
end