Sha256: d0efb2e6375f4f30fd8a94f48b7c944c49c567bf51a7774f038c244c6d12ad63

Contents?: true

Size: 764 Bytes

Versions: 1

Compression:

Stored size: 764 Bytes

Contents

module Xmldsig_fiscalizer
  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, instruct = true, &block)
      signatures.each { |signature| signature.sign(private_key, &block) }
      instruct ? @document.to_s : @document.root.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

1 entries across 1 versions & 1 rubygems

Version Path
xmldsig-fiscalizer-0.2.5 lib/xmldsig_fiscalizer/signed_document.rb