Class: Xmldsig::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/xmldsig/reference.rb

Defined Under Namespace

Classes: ReferencedNodeNotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reference) ⇒ Reference

Returns a new instance of Reference.



7
8
9
10
# File 'lib/xmldsig/reference.rb', line 7

def initialize(reference)
  @reference = reference
  @errors = []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'lib/xmldsig/reference.rb', line 3

def errors
  @errors
end

#referenceObject

Returns the value of attribute reference.



3
4
5
# File 'lib/xmldsig/reference.rb', line 3

def reference
  @reference
end

Instance Method Details

#digest_valueObject



39
40
41
# File 'lib/xmldsig/reference.rb', line 39

def digest_value
  Base64.decode64 reference.at_xpath("descendant::ds:DigestValue", Xmldsig::NAMESPACES).content
end

#documentObject



43
44
45
# File 'lib/xmldsig/reference.rb', line 43

def document
  reference.document
end

#reference_uriObject



35
36
37
# File 'lib/xmldsig/reference.rb', line 35

def reference_uri
  reference.get_attribute("URI")
end

#referenced_nodeObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/xmldsig/reference.rb', line 22

def referenced_node
  if reference_uri && reference_uri != ""
    id = reference_uri[1..-1]
    if ref = document.dup.at_xpath("//*[@Id|@ID='#{id}' or @wsu:Id='#{id}']", Xmldsig::NAMESPACES)
      ref
    else
      raise(ReferencedNodeNotFound, "Could not find the referenced node #{id}")
    end
  else
    document.dup.root
  end
end

#signObject



12
13
14
# File 'lib/xmldsig/reference.rb', line 12

def sign
  self.digest_value = calculate_digest_value
end

#validate_digest_valueObject



16
17
18
19
20
# File 'lib/xmldsig/reference.rb', line 16

def validate_digest_value
  unless digest_value == calculate_digest_value
    @errors << :digest_value
  end
end