Class: COSE::Sign

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

Constant Summary collapse

CONTEXT =
"Signature"

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:, signatures:, **keyword_arguments) ⇒ Sign

Returns a new instance of Sign.



22
23
24
25
26
27
# File 'lib/cose/sign.rb', line 22

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

  @payload = payload
  @signatures = signatures
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



12
13
14
# File 'lib/cose/sign.rb', line 12

def payload
  @payload
end

#signaturesObject (readonly)

Returns the value of attribute signatures.



12
13
14
# File 'lib/cose/sign.rb', line 12

def signatures
  @signatures
end

Class Method Details

.keyword_arguments_for_initialize(decoded) ⇒ Object



14
15
16
# File 'lib/cose/sign.rb', line 14

def self.keyword_arguments_for_initialize(decoded)
  { payload: decoded[0], signatures: decoded[1].map { |s| COSE::Signature.from_array(s) } }
end

.tagObject



18
19
20
# File 'lib/cose/sign.rb', line 18

def self.tag
  98
end

Instance Method Details

#verify(key, external_aad = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/cose/sign.rb', line 29

def verify(key, external_aad = nil)
  signature = signatures.detect { |s| s.headers.kid == key.kid }

  if signature
    signature.algorithm.verify(key, signature.signature, verification_data(signature, external_aad))
  else
    raise(COSE::Error, "No signature matches key kid")
  end
end