Class: SignedXml::Reference

Inherits:
Object
  • Object
show all
Includes:
Logging, Transformable
Defined in:
lib/signed_xml/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger

Methods included from Transformable

#apply_transforms, #transforms

Constructor Details

#initialize(here) ⇒ Reference

Returns a new instance of Reference.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/signed_xml/reference.rb', line 8

def initialize(here)
  @here = here

  uri = here['URI']
  case uri
  when nil, ""
    @start = here.document.root
  when /^#/
    id = uri.split('#').last
    raise ArgumentError, "XPointer expressions like #{id} are not yet supported" if id =~ /^xpointer/
    # TODO: handle ID attrs with names other than 'ID'
    @start = here.document.at_xpath("//*[@ID='#{id}']")
    raise ArgumentError, "no match found for ID #{id}" if @start.nil?
  else
    raise ArgumentError, "unsupported Reference URI #{uri}"
  end

  @transforms = init_transforms
end

Instance Attribute Details

#hereObject (readonly)

Returns the value of attribute here.


6
7
8
# File 'lib/signed_xml/reference.rb', line 6

def here
  @here
end

#startObject (readonly)

Returns the value of attribute start.


6
7
8
# File 'lib/signed_xml/reference.rb', line 6

def start
  @start
end

Instance Method Details

#compute_and_set_digest_valueObject


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

def compute_and_set_digest_value
  digest_value_node.content = apply_transforms
  logger.debug "set digest value to [#{digest_value}]"
end

#is_verified?Boolean

Returns:

  • (Boolean)

28
29
30
31
32
# File 'lib/signed_xml/reference.rb', line 28

def is_verified?
  result = apply_transforms == digest_value
  logger.info "verification failed for digest value [#{digest_value}]" unless result
  result
end