Class: AttrVault::Key

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, value) ⇒ Key

Returns a new instance of Key.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/attr_vault/keyring.rb', line 5

def initialize(id, value)
  if value.nil? || value.empty?
    raise InvalidKey, "key value required"
  end
  begin
    id = Integer(id)
  rescue
    raise InvalidKey, "key id must be an integer"
  end

  @id = id
  @value = value
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/attr_vault/keyring.rb', line 3

def id
  @id
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/attr_vault/keyring.rb', line 3

def value
  @value
end

Instance Method Details

#digest(data) ⇒ Object



19
20
21
# File 'lib/attr_vault/keyring.rb', line 19

def digest(data)
  AttrVault::Encryption::hmac_digest(value, data)
end

#to_json(*args) ⇒ Object



23
24
25
# File 'lib/attr_vault/keyring.rb', line 23

def to_json(*args)
  { id: id, value: value }.to_json
end