Class: InformationCard::Decrypter
- Inherits:
-
Object
- Object
- InformationCard::Decrypter
- Defined in:
- lib/information_card/decrypter.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #decrypt ⇒ Object
-
#initialize(encrypted_information_card_xml, certificate_location, certificate_subject) ⇒ Decrypter
constructor
A new instance of Decrypter.
- #valid? ⇒ Boolean
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
#errors ⇒ Object (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
#decrypt ⇒ Object
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
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 |