Class: KStor::Model::Secret

Inherits:
Base
  • Object
show all
Defined in:
lib/kstor/model.rb

Overview

A secret, with metadata and a value that are kept encrypted on disk.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#clean, #dirty?, #initialize, property, property?

Constructor Details

This class inherits a constructor from KStor::Model::Base

Instance Attribute Details

#ciphertextObject

Returns value of property ciphertext

Returns:

  • returns value of property ciphertext



378
# File 'lib/kstor/model.rb', line 378

property :ciphertext

#encrypted_metadataObject

Returns value of property encrypted_metadata

Returns:

  • returns value of property encrypted_metadata



382
# File 'lib/kstor/model.rb', line 382

property :encrypted_metadata

#group_idObject

Returns value of property group_id

Returns:

  • returns value of property group_id



376
# File 'lib/kstor/model.rb', line 376

property :group_id

#idObject

Returns value of property id

Returns:

  • returns value of property id



370
# File 'lib/kstor/model.rb', line 370

property :id

#meta_author_idObject

Returns value of property meta_author_id

Returns:

  • returns value of property meta_author_id



374
# File 'lib/kstor/model.rb', line 374

property :meta_author_id

#metadataObject

Returns value of property metadata

Returns:

  • returns value of property metadata



384
# File 'lib/kstor/model.rb', line 384

property :metadata, read_only: true

#plaintextObject

Returns value of property plaintext

Returns:

  • returns value of property plaintext



380
# File 'lib/kstor/model.rb', line 380

property :plaintext

#value_author_idObject

Returns value of property value_author_id

Returns:

  • returns value of property value_author_id



372
# File 'lib/kstor/model.rb', line 372

property :value_author_id

Instance Method Details

#lockObject

Forget about the decrypted value and metadata.



419
420
421
422
# File 'lib/kstor/model.rb', line 419

def lock
  self. = nil
  self.plaintext = nil
end

#to_hObject



426
427
428
429
430
431
432
433
434
# File 'lib/kstor/model.rb', line 426

def to_h
  h = super
  h.delete('ciphertext')
  h.delete('encrypted_metadata')
  h.delete('value_author_id')
  h.delete('meta_author_id')

  h
end

#unlock(author_pubk, group_privk) ⇒ Object

Decrypt secret value.

This will set the #plaintext property.

Parameters:



398
399
400
401
402
# File 'lib/kstor/model.rb', line 398

def unlock(author_pubk, group_privk)
  self.plaintext = Crypto.decrypt_secret_value(
    author_pubk, group_privk, ciphertext
  )
end

#unlock_metadata(author_pubk, group_privk) ⇒ Object

Decrypt secret metadata.

This will set the #metadata property.

Parameters:



412
413
414
415
416
# File 'lib/kstor/model.rb', line 412

def (author_pubk, group_privk)
  self. = Crypto.(
    author_pubk, group_privk, 
  )
end