Class: COSE::Mac

Inherits:
Mac0 show all
Defined in:
lib/cose/mac.rb

Constant Summary collapse

CONTEXT =
"MAC"

Constants inherited from SecurityMessage

SecurityMessage::ZERO_LENGTH_BIN_STRING

Instance Attribute Summary collapse

Attributes inherited from Mac0

#payload, #tag

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(recipients:, **keyword_arguments) ⇒ Mac

Returns a new instance of Mac.



20
21
22
23
24
# File 'lib/cose/mac.rb', line 20

def initialize(recipients:, **keyword_arguments)
  super(**keyword_arguments)

  @recipients = recipients
end

Instance Attribute Details

#recipientsObject (readonly)

Returns the value of attribute recipients.



10
11
12
# File 'lib/cose/mac.rb', line 10

def recipients
  @recipients
end

Class Method Details

.keyword_arguments_for_initialize(decoded) ⇒ Object



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

def self.keyword_arguments_for_initialize(decoded)
  super.merge(recipients: decoded.last.map { |r| COSE::Recipient.from_array(r) })
end

.tagObject



16
17
18
# File 'lib/cose/mac.rb', line 16

def self.tag
  97
end

Instance Method Details

#verify(key, external_aad = nil) ⇒ Object



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

def verify(key, external_aad = nil)
  recipient = recipients.detect { |r| r.headers.kid == key.kid }

  if recipient
    super
  else
    raise(COSE::Error, "No recipient match the key")
  end
end