Sha256: 0642c6ccf56236f39eeed6804e788f576c84f6a3fa7574aa51153ce8f75227f7

Contents?: true

Size: 703 Bytes

Versions: 2

Compression:

Stored size: 703 Bytes

Contents

module Xmldsig
  class SignedDocument
    attr_accessor :document

    def initialize(document, options = {})
      @document = Nokogiri::XML::Document.parse(document)
    end

    def validate(certificate = nil, &block)
      signatures.any? && signatures.all? { |signature| signature.valid?(certificate, &block) }
    end

    def sign(private_key = nil, &block)
      signatures.each { |signature| signature.sign(private_key, &block) }
      @document.to_s
    end

    def signed_nodes
      signatures.flat_map(&:references).map(&:referenced_node)
    end

    def signatures
      document.xpath("//ds:Signature", NAMESPACES).reverse.collect { |node| Signature.new(node) } || []
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
xmldsig-0.2.2 lib/xmldsig/signed_document.rb
xmldsig-0.2.1 lib/xmldsig/signed_document.rb