Class: WSDL::Security::Reference

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

Overview

Represents a signed reference in an XML Digital Signature.

A Reference identifies an element to be signed and contains its computed digest value. References are collected during the signing process and included in the SignedInfo element.

Examples:

Creating a reference

reference = Reference.new(
  id: 'Body-abc123',
  digest_value: 'base64_digest_here'
)

With inclusive namespaces

reference = Reference.new(
  id: 'Body-abc123',
  digest_value: 'base64_digest_here',
  inclusive_namespaces: ['soap', 'wsu']
)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, digest_value:, inclusive_namespaces: nil) ⇒ Reference

Creates a new Reference instance.

Parameters:

  • id (String)

    the wsu:Id of the referenced element

  • digest_value (String)

    the Base64-encoded digest of the canonicalized element

  • inclusive_namespaces (Array<String>, nil) (defaults to: nil)

    namespace prefixes for C14N



45
46
47
48
49
# File 'lib/wsdl/security/reference.rb', line 45

def initialize(id:, digest_value:, inclusive_namespaces: nil)
  @id = id
  @digest_value = digest_value
  @inclusive_namespaces = inclusive_namespaces
end

Instance Attribute Details

#digest_valueString (readonly)

Returns the Base64-encoded digest value.

Returns:

  • (String)


33
34
35
# File 'lib/wsdl/security/reference.rb', line 33

def digest_value
  @digest_value
end

#idString (readonly)

Returns the element ID (without the # prefix).

Returns:

  • (String)


29
30
31
# File 'lib/wsdl/security/reference.rb', line 29

def id
  @id
end

#inclusive_namespacesArray<String>? (readonly)

Returns the list of namespace prefixes for inclusive canonicalization.

Returns:

  • (Array<String>, nil)


37
38
39
# File 'lib/wsdl/security/reference.rb', line 37

def inclusive_namespaces
  @inclusive_namespaces
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Compares two references for equality.

Parameters:

Returns:

  • (Boolean)

    true if references are equal



97
98
99
100
101
102
103
# File 'lib/wsdl/security/reference.rb', line 97

def ==(other)
  return false unless other.is_a?(Reference)

  @id == other.id &&
    @digest_value == other.digest_value &&
    @inclusive_namespaces == other.inclusive_namespaces
end

#hashInteger

Returns a hash code for the reference.

Returns:

  • (Integer)

    the hash code



110
111
112
# File 'lib/wsdl/security/reference.rb', line 110

def hash
  [@id, @digest_value, @inclusive_namespaces].hash
end

#inclusive_namespaces?Boolean

Returns whether this reference has inclusive namespaces specified.

Returns:

  • (Boolean)

    true if inclusive namespaces are present



63
64
65
# File 'lib/wsdl/security/reference.rb', line 63

def inclusive_namespaces?
  @inclusive_namespaces&.any? || false
end

#prefix_listString?

Returns the inclusive namespaces as a space-separated string.

This is the format required for the PrefixList attribute in the InclusiveNamespaces element.

Returns:

  • (String, nil)

    the prefix list or nil if no namespaces



74
75
76
77
78
# File 'lib/wsdl/security/reference.rb', line 74

def prefix_list
  return nil unless inclusive_namespaces?

  @inclusive_namespaces.join(' ')
end

#to_hHash

Returns a Hash representation of the reference.

Returns:

  • (Hash)

    the reference data as a hash



84
85
86
87
88
89
90
# File 'lib/wsdl/security/reference.rb', line 84

def to_h
  {
    id: @id,
    digest_value: @digest_value,
    inclusive_namespaces: @inclusive_namespaces
  }
end

#uriString

Returns the URI reference for use in the Reference element.

Returns:

  • (String)

    the URI with # prefix (e.g., '#Body-abc123')



55
56
57
# File 'lib/wsdl/security/reference.rb', line 55

def uri
  "##{@id}"
end