Class: SecureYaml::YamlDecrypter

Inherits:
Object
  • Object
show all
Defined in:
lib/secure_yaml/yaml_decrypter.rb

Instance Method Summary collapse

Constructor Details

#initialize(decryption_algorithm, secret_key) ⇒ YamlDecrypter

Returns a new instance of YamlDecrypter.



7
8
9
10
# File 'lib/secure_yaml/yaml_decrypter.rb', line 7

def initialize(decryption_algorithm, secret_key)
  @decryption_algorithm = decryption_algorithm
  @secret_key = secret_key
end

Instance Method Details

#decrypt(yaml) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/secure_yaml/yaml_decrypter.rb', line 12

def decrypt(yaml)
  case yaml
    when Hash
      yaml.inject({}) {|new_hash, (key, value)| new_hash[key] = decrypt(value); new_hash}
    when String
      yaml.gsub(/\b#{ENCRYPTED_PROPERTY_WRAPPER_ID}\((.*)\)(?:\b|$)/) {@decryption_algorithm.decrypt(@secret_key, $1)}
    when Array
      yaml.map {|element| decrypt(element)}
    else
      yaml
  end
end