Class: SignedXml::Document

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/signed_xml/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger

Constructor Details

#initialize(thing) ⇒ Document

Returns a new instance of Document.



10
11
12
13
14
15
16
# File 'lib/signed_xml/document.rb', line 10

def initialize(thing)
  if thing.is_a? Nokogiri::XML::Document
    @doc = thing
  else
    @doc = Nokogiri::XML(thing)
  end      
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



8
9
10
# File 'lib/signed_xml/document.rb', line 8

def doc
  @doc
end

Instance Method Details

#is_verifiable?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/signed_xml/document.rb', line 18

def is_verifiable?
  signatures.any?
end

#is_verified?(arg = nil) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/signed_xml/document.rb', line 22

def is_verified?(arg = nil)
  unless is_verifiable?        
    logger.warn "document cannot be verified because it contains no <Signature> elements"
    return false
  end

  if arg.respond_to? :public_key
    set_public_key_for_signatures(arg)
  elsif arg.respond_to? :has_key?
    set_certificate_store_for_signatures(arg)
  elsif !arg.nil?
    raise ArgumentError, "#{arg.inspect}:#{arg.class} must have a public key or be a hash of public keys"
  end

  signatures.all?(&:is_verified?)
end

#sign(private_key, certificate = nil) ⇒ Object



39
40
41
42
# File 'lib/signed_xml/document.rb', line 39

def sign(private_key, certificate = nil)
  signatures.each { |sig| sig.sign(private_key, certificate) }
  self
end

#to_xmlObject



44
45
46
# File 'lib/signed_xml/document.rb', line 44

def to_xml
  doc.to_xml
end