Class: Xmlenc::EncryptedDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlenc/encrypted_document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ EncryptedDocument

Returns a new instance of EncryptedDocument.



5
6
7
# File 'lib/xmlenc/encrypted_document.rb', line 5

def initialize(xml)
  @xml = xml
end

Instance Attribute Details

#xmlObject

Returns the value of attribute xml.



3
4
5
# File 'lib/xmlenc/encrypted_document.rb', line 3

def xml
  @xml
end

Instance Method Details

#decrypt(key) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/xmlenc/encrypted_document.rb', line 17

def decrypt(key)
  encrypted_keys.each do |encrypted_key|
    encrypted_data = encrypted_key.encrypted_data
    data_key       = encrypted_key.decrypt(key)
    encrypted_data.decrypt(data_key)
  end
  @document.to_xml
end

#documentObject



9
10
11
# File 'lib/xmlenc/encrypted_document.rb', line 9

def document
  @document ||= Nokogiri::XML::Document.parse(xml)
end

#encrypted_keysObject



13
14
15
# File 'lib/xmlenc/encrypted_document.rb', line 13

def encrypted_keys
  document.xpath('//xenc:EncryptedKey', NAMESPACES).collect { |n| EncryptedKey.new(n) }
end