Class: WSDL::Security::SignatureOptions

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

Overview

Value object encapsulating signature configuration options.

This class extracts and validates the various options that can be passed to Config#signature, providing a clean interface for accessing signature-related settings.

Examples:

Creating from a hash

options = SignatureOptions.from_hash(
  sign_timestamp: true,
  sign_addressing: true,
  key_reference: :issuer_serial
)

Checking options

options.sign_addressing?        # => true
options.key_reference           # => :issuer_serial

Constant Summary collapse

DEFAULTS =

Default values for signature options

{
  sign_timestamp: true,
  sign_addressing: false,
  explicit_namespace_prefixes: false,
  key_reference: Constants::KeyReference::BINARY_SECURITY_TOKEN,
  digest_algorithm: :sha256
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ SignatureOptions

Creates a new SignatureOptions instance.

Parameters:

  • options (Hash)

    the signature options

Options Hash (**options):

  • :sign_timestamp (Boolean)

    whether to sign the timestamp

  • :sign_addressing (Boolean)

    whether to sign WS-Addressing headers

  • :explicit_namespace_prefixes (Boolean)

    whether to use explicit ns prefixes

  • :key_reference (Symbol)

    how to reference the signing certificate

  • :digest_algorithm (Symbol)

    the digest algorithm to use



47
48
49
50
51
52
53
# File 'lib/wsdl/security/signature_options.rb', line 47

def initialize(**options)
  @sign_timestamp = options[:sign_timestamp]
  @sign_addressing = options[:sign_addressing]
  @explicit_namespace_prefixes = options[:explicit_namespace_prefixes]
  @key_reference = options[:key_reference]
  @digest_algorithm = options[:digest_algorithm]
end

Instance Attribute Details

#digest_algorithmSymbol (readonly)

Returns the digest algorithm (:sha1, :sha256, :sha512).

Returns:

  • (Symbol)

    the digest algorithm (:sha1, :sha256, :sha512)



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

def digest_algorithm
  @digest_algorithm
end

#key_referenceSymbol (readonly)

Returns the key reference method.

Returns:

  • (Symbol)

    the key reference method



36
37
38
# File 'lib/wsdl/security/signature_options.rb', line 36

def key_reference
  @key_reference
end

Class Method Details

.from_hash(options) ⇒ SignatureOptions

Creates a SignatureOptions instance from a hash of options.

This method applies default values for any missing options.

Parameters:

  • options (Hash)

    the options hash

Returns:



62
63
64
65
66
67
68
69
70
71
# File 'lib/wsdl/security/signature_options.rb', line 62

def self.from_hash(options)
  new(
    sign_timestamp: options.fetch(:sign_timestamp, DEFAULTS[:sign_timestamp]),
    sign_addressing: options.fetch(:sign_addressing, DEFAULTS[:sign_addressing]),
    explicit_namespace_prefixes: options.fetch(:explicit_namespace_prefixes,
                                               DEFAULTS[:explicit_namespace_prefixes]),
    key_reference: options.fetch(:key_reference, DEFAULTS[:key_reference]),
    digest_algorithm: options.fetch(:digest_algorithm, DEFAULTS[:digest_algorithm])
  )
end

Instance Method Details

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

Compares two SignatureOptions for equality.

Parameters:

Returns:

  • (Boolean)

    true if options are equal



116
117
118
119
120
# File 'lib/wsdl/security/signature_options.rb', line 116

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

  to_h == other.to_h
end

#explicit_namespace_prefixes?Boolean

Returns whether explicit namespace prefixes should be used.

Returns:

  • (Boolean)


93
94
95
# File 'lib/wsdl/security/signature_options.rb', line 93

def explicit_namespace_prefixes?
  @explicit_namespace_prefixes == true
end

#hashInteger

Returns a hash code for the options.

Returns:

  • (Integer)

    the hash code



127
128
129
# File 'lib/wsdl/security/signature_options.rb', line 127

def hash
  to_h.hash
end

#sign_addressing?Boolean

Returns whether WS-Addressing headers should be signed.

Returns:

  • (Boolean)


85
86
87
# File 'lib/wsdl/security/signature_options.rb', line 85

def sign_addressing?
  @sign_addressing == true
end

#sign_timestamp?Boolean

Returns whether the timestamp should be signed.

Returns:

  • (Boolean)


77
78
79
# File 'lib/wsdl/security/signature_options.rb', line 77

def sign_timestamp?
  @sign_timestamp == true
end

#to_hHash

Returns a Hash representation of the options.

Returns:

  • (Hash)

    the options as a hash



101
102
103
104
105
106
107
108
109
# File 'lib/wsdl/security/signature_options.rb', line 101

def to_h
  {
    sign_timestamp: @sign_timestamp,
    sign_addressing: @sign_addressing,
    explicit_namespace_prefixes: @explicit_namespace_prefixes,
    key_reference: @key_reference,
    digest_algorithm: @digest_algorithm
  }
end