Class: COSE::Sign
- Inherits:
-
SecurityMessage
- Object
- SecurityMessage
- COSE::Sign
- 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
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#signatures ⇒ Object
readonly
Returns the value of attribute signatures.
Attributes inherited from SecurityMessage
#protected_headers, #unprotected_headers
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(payload:, signatures:, **keyword_arguments) ⇒ Sign
constructor
A new instance of Sign.
- #verify(key, external_aad = nil) ⇒ Object
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
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
12 13 14 |
# File 'lib/cose/sign.rb', line 12 def payload @payload end |
#signatures ⇒ Object (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 |
.tag ⇒ Object
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 |