Sha256: 5b502ac6634c384ad88b87aa635898187bcc6530c0de5cf0efb5f7aba464f16e

Contents?: true

Size: 748 Bytes

Versions: 11

Compression:

Stored size: 748 Bytes

Contents

module Xmlenc
  class EncryptedDocument
    attr_accessor :xml

    def initialize(xml)
      @xml = xml
    end

    def document
      @document ||= Nokogiri::XML(xml, nil, nil, Nokogiri::XML::ParseOptions::STRICT)
    end

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

    def decrypt(key, fail_silent = false)
      encrypted_keys.each do |encrypted_key|
        begin
          encrypted_data = encrypted_key.encrypted_data
          data_key       = encrypted_key.decrypt(key)
          encrypted_data.decrypt(data_key)
        rescue OpenSSL::PKey::RSAError => e
          raise e unless fail_silent
        end
      end
      @document.to_xml
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
xmlenc-0.8.0 lib/xmlenc/encrypted_document.rb
xmlenc-0.7.1 lib/xmlenc/encrypted_document.rb
xmlenc-0.7.0 lib/xmlenc/encrypted_document.rb
xmlenc-0.6.9 lib/xmlenc/encrypted_document.rb
xmlenc-0.6.8 lib/xmlenc/encrypted_document.rb
xmlenc-0.6.6 lib/xmlenc/encrypted_document.rb
xmlenc-0.6.5 lib/xmlenc/encrypted_document.rb
xmlenc-0.6.4 lib/xmlenc/encrypted_document.rb
xmlenc-0.6.3 lib/xmlenc/encrypted_document.rb
xmlenc-0.6.2 lib/xmlenc/encrypted_document.rb
xmlenc-0.6.1 lib/xmlenc/encrypted_document.rb