Class: SecureDBFields::Keyring
- Inherits:
-
Object
- Object
- SecureDBFields::Keyring
- Defined in:
- lib/secure_db_fields/keys.rb
Constant Summary collapse
- DEFAULT_PATH =
"/etc/secure_db_fields/keys.env"
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #active_key_id ⇒ Object
- #blind_index_key(domain = nil) ⇒ Object
- #encryption_key(key_id = 1) ⇒ Object
-
#initialize(path = ENV.fetch("SECURE_DB_FIELDS_KEY_FILE", DEFAULT_PATH)) ⇒ Keyring
constructor
A new instance of Keyring.
Constructor Details
#initialize(path = ENV.fetch("SECURE_DB_FIELDS_KEY_FILE", DEFAULT_PATH)) ⇒ Keyring
Returns a new instance of Keyring.
9 10 11 12 |
# File 'lib/secure_db_fields/keys.rb', line 9 def initialize(path = ENV.fetch("SECURE_DB_FIELDS_KEY_FILE", DEFAULT_PATH)) @path = path @values = parse_file(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/secure_db_fields/keys.rb', line 7 def path @path end |
Instance Method Details
#active_key_id ⇒ Object
29 30 31 32 |
# File 'lib/secure_db_fields/keys.rb', line 29 def active_key_id value = @values["SDF_ACTIVE_KEY_ID"] value ? Integer(value) : 1 end |
#blind_index_key(domain = nil) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/secure_db_fields/keys.rb', line 20 def blind_index_key(domain = nil) if domain && !domain.to_s.empty? name = "SDF_BIDX_#{normalize_domain(domain)}_KEY_HEX" fetch_hex_key(name) || raise(KeyError, "missing blind-index key #{name}") else fetch_hex_key("SDF_BIDX_KEY_HEX") || raise(KeyError, "missing SDF_BIDX_KEY_HEX") end end |
#encryption_key(key_id = 1) ⇒ Object
14 15 16 17 18 |
# File 'lib/secure_db_fields/keys.rb', line 14 def encryption_key(key_id = 1) fetch_hex_key("SDF_ENC_KEY_#{Integer(key_id)}_HEX") || (Integer(key_id) == 1 ? fetch_hex_key("SDF_ENC_KEY_HEX") : nil) || raise(KeyError, "missing encryption key for key_id=#{key_id}") end |