Class: InformationCard::Decrypter

Inherits:
Object
  • Object
show all
Defined in:
lib/information_card/decrypter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encrypted_information_card_xml, certificate_location, certificate_subject) ⇒ Decrypter

Returns a new instance of Decrypter.



6
7
8
9
10
11
# File 'lib/information_card/decrypter.rb', line 6

def initialize(encrypted_information_card_xml, certificate_location, certificate_subject)
  @xml_document = REXML::Document.new(encrypted_information_card_xml)
  @certificate_location = certificate_location
  @certificate_subject = certificate_subject
  @errors = {}      
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/information_card/decrypter.rb', line 4

def errors
  @errors
end

Instance Method Details

#decryptObject



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

def decrypt
  private_key = CertificateUtil.lookup_private_key(@certificate_location, @certificate_subject)      
  encrypted_data = REXML::XPath.first(@xml_document, "enc:EncryptedData", {"enc" => Namespaces::XENC})
  key_info = REXML::XPath.first(encrypted_data, "x:KeyInfo", {"x" => Namespaces::DS})   
  encrypted_key = REXML::XPath.first(key_info, "e:EncryptedKey", {"e" => Namespaces::XENC})
  key_cipher = REXML::XPath.first(encrypted_key, "e:CipherData/e:CipherValue", {"e" => Namespaces::XENC})
  key = decrypt_key(key_cipher.text, private_key)

  cipher_data = REXML::XPath.first(@xml_document, "enc:EncryptedData/enc:CipherData/enc:CipherValue", {"enc" => Namespaces::XENC})
  decrypt_cipher_data(key, cipher_data.text)
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/information_card/decrypter.rb', line 25

def valid?
  # TODO: Should perform more validation and handle errors more gracefully.
  #       ex. What if algorithm is not supported?
  errors.empty?
end