Class: Net::HTTP::MessageSignatures::Signature

Inherits:
Object
  • Object
show all
Includes:
StructuredFieldValues
Defined in:
lib/net/http/message_signatures/signature.rb

Overview

An HTTP Message Signature with its covered components and parameters.

Defined Under Namespace

Classes: VerificationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature: nil, covered_components: {}, params: {}, algorithm: nil) ⇒ Signature

Returns a new instance of Signature.

Parameters:

  • signature (String) (defaults to: nil)

    signature value in binary

  • covered_components (Hash{String, ParameterizedValue => String}) (defaults to: {})

    map of covered components’ name (and optional params) and value

  • params (Hash{String => Object}) (defaults to: {})

    map of signature parameters’ name and value

  • algorithm (SignatureAlgorithm) (defaults to: nil)

    signature algorithm which can be used without key material



31
32
33
34
35
36
# File 'lib/net/http/message_signatures/signature.rb', line 31

def initialize(signature: nil, covered_components: {}, params: {}, algorithm: nil)
  @signature = signature
  @covered_components = covered_components
  @params = params
  @algorithm = algorithm
end

Instance Attribute Details

#algorithm=(value) ⇒ SignatureAlgorithm

Returns signature algorithm which can be used without key material.

Returns:



24
25
26
# File 'lib/net/http/message_signatures/signature.rb', line 24

def algorithm=(value)
  @algorithm = value
end

#covered_componentsHash{String, ParameterizedValue => String} (readonly)

Returns map of covered components’ name (and optional params) and value.

Returns:

  • (Hash{String, ParameterizedValue => String})

    map of covered components’ name (and optional params) and value



20
21
22
# File 'lib/net/http/message_signatures/signature.rb', line 20

def covered_components
  @covered_components
end

#paramsHash{String => Object} (readonly)

Returns map of signature parameters’ name and value.

Returns:

  • (Hash{String => Object})

    map of signature parameters’ name and value



22
23
24
# File 'lib/net/http/message_signatures/signature.rb', line 22

def params
  @params
end

#signatureString?

Returns signature value in binary.

Returns:

  • (String, nil)

    signature value in binary



17
18
19
# File 'lib/net/http/message_signatures/signature.rb', line 17

def signature
  @signature
end

Instance Method Details

#verify!Object

Verifies the signature. Will raise error if it is invalid.



42
43
44
45
46
# File 'lib/net/http/message_signatures/signature.rb', line 42

def verify!
  return if algorithm.verify(signature_base, signature)

  raise VerificationError, 'signature verification failed'
end