Class: COSE::Sign1

Inherits:
SecurityMessage show all
Defined in:
lib/cose/sign1.rb

Constant Summary collapse

CONTEXT =
"Signature1"

Constants inherited from SecurityMessage

COSE::SecurityMessage::ZERO_LENGTH_BIN_STRING

Instance Attribute Summary collapse

Attributes inherited from SecurityMessage

#protected_headers, #unprotected_headers

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SecurityMessage

#algorithm, deserialize, deserialize_headers, from_array, #headers

Constructor Details

#initialize(payload:, signature:, **keyword_arguments) ⇒ Sign1

Returns a new instance of Sign1.



21
22
23
24
25
26
# File 'lib/cose/sign1.rb', line 21

def initialize(payload:, signature:, **keyword_arguments)
  super(**keyword_arguments)

  @payload = payload
  @signature = signature
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



11
12
13
# File 'lib/cose/sign1.rb', line 11

def payload
  @payload
end

#signatureObject (readonly)

Returns the value of attribute signature.



11
12
13
# File 'lib/cose/sign1.rb', line 11

def signature
  @signature
end

Class Method Details

.keyword_arguments_for_initialize(decoded) ⇒ Object



13
14
15
# File 'lib/cose/sign1.rb', line 13

def self.keyword_arguments_for_initialize(decoded)
  { payload: decoded[0], signature: decoded[1] }
end

.tagObject



17
18
19
# File 'lib/cose/sign1.rb', line 17

def self.tag
  18
end

Instance Method Details

#verify(key, external_aad = nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/cose/sign1.rb', line 28

def verify(key, external_aad = nil)
  if key.kid == headers.kid
    algorithm.verify(key, signature, verification_data(external_aad))
  else
    raise(COSE::Error, "Non matching kid")
  end
end