Class: SimpleCrypt::Secret

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret_data = nil, iv = nil, salt = nil, auth_tag = nil, auth_data = nil) ⇒ Secret

Returns a new instance of Secret.



8
9
10
11
12
13
14
# File 'lib/simple_crypt/secret.rb', line 8

def initialize(secret_data = nil, iv = nil, salt = nil, auth_tag = nil, auth_data = nil)
  @secret_data = secret_data
  @iv = iv
  @salt = salt
  @auth_tag = auth_tag
  @auth_data = auth_data
end

Instance Attribute Details

#auth_dataObject

Returns the value of attribute auth_data.



6
7
8
# File 'lib/simple_crypt/secret.rb', line 6

def auth_data
  @auth_data
end

#auth_tagObject

Returns the value of attribute auth_tag.



6
7
8
# File 'lib/simple_crypt/secret.rb', line 6

def auth_tag
  @auth_tag
end

#ivObject

Returns the value of attribute iv.



6
7
8
# File 'lib/simple_crypt/secret.rb', line 6

def iv
  @iv
end

#saltObject

Returns the value of attribute salt.



6
7
8
# File 'lib/simple_crypt/secret.rb', line 6

def salt
  @salt
end

#secret_dataObject

Returns the value of attribute secret_data.



6
7
8
# File 'lib/simple_crypt/secret.rb', line 6

def secret_data
  @secret_data
end

Class Method Details

.load(json) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/simple_crypt/secret.rb', line 20

def self.load(json)
  data = JSON.parse(json)
  s = new(
    data['@secret_data'],
    data['@iv'],
    data['@salt'],
    data['@auth_tag'],
    data['@auth_data']
  )
  s
end

Instance Method Details

#to_jsonObject



16
17
18
# File 'lib/simple_crypt/secret.rb', line 16

def to_json
  JSON.generate(Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }])
end