Class: CredStash::Secret
- Inherits:
-
Object
- Object
- CredStash::Secret
- Defined in:
- lib/cred_stash/secret.rb
Instance Attribute Summary collapse
-
#encrypted_value ⇒ Object
readonly
Returns the value of attribute encrypted_value.
-
#hmac ⇒ Object
readonly
Returns the value of attribute hmac.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #decrypted_value ⇒ Object
- #encrypt! ⇒ Object
- #falsified? ⇒ Boolean
-
#initialize(name:, value: nil, key: nil, encrypted_value: nil, hmac: nil) ⇒ Secret
constructor
A new instance of Secret.
- #save ⇒ Object
Constructor Details
#initialize(name:, value: nil, key: nil, encrypted_value: nil, hmac: nil) ⇒ Secret
4 5 6 7 8 9 10 |
# File 'lib/cred_stash/secret.rb', line 4 def initialize(name:, value: nil, key: nil, encrypted_value: nil, hmac: nil) @name = name @value = value @key = key @encrypted_value = encrypted_value @hmac = hmac end |
Instance Attribute Details
#encrypted_value ⇒ Object (readonly)
Returns the value of attribute encrypted_value.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def encrypted_value @encrypted_value end |
#hmac ⇒ Object (readonly)
Returns the value of attribute hmac.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def hmac @hmac end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def value @value end |
Class Method Details
.find(name) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/cred_stash/secret.rb', line 31 def find(name) item = repository.get(name) new( name: name, key: CredStash::CipherKey.decrypt(Base64.decode64(item.key)), encrypted_value: Base64.decode64(item.contents), hmac: item.hmac ) end |
.repository ⇒ Object
41 42 43 |
# File 'lib/cred_stash/secret.rb', line 41 def repository CredStash::Repository.new end |
Instance Method Details
#decrypted_value ⇒ Object
26 27 28 |
# File 'lib/cred_stash/secret.rb', line 26 def decrypted_value @key.decrypt(@encrypted_value) end |
#encrypt! ⇒ Object
12 13 14 15 16 |
# File 'lib/cred_stash/secret.rb', line 12 def encrypt! @key = CredStash::CipherKey.generate @encrypted_value = @key.encrypt(@value) @hmac = @key.hmac(@encrypted_value) end |
#falsified? ⇒ Boolean
22 23 24 |
# File 'lib/cred_stash/secret.rb', line 22 def falsified? @key.hmac(@encrypted_value) == @hmac end |
#save ⇒ Object
18 19 20 |
# File 'lib/cred_stash/secret.rb', line 18 def save self.class.repository.put(to_item) end |