Class: COSE::Key::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cose/key/base.rb

Direct Known Subclasses

CurveKey, RSA, Symmetric

Constant Summary collapse

LABEL_BASE_IV =
5
LABEL_KEY_OPS =
4
LABEL_ALG =
3
LABEL_KID =
2
LABEL_KTY =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kid: nil, alg: nil, key_ops: nil, base_iv: nil) ⇒ Base

Returns a new instance of Base.



32
33
34
35
36
37
# File 'lib/cose/key/base.rb', line 32

def initialize(kid: nil, alg: nil, key_ops: nil, base_iv: nil)
  @kid = kid
  @alg = alg
  @key_ops = key_ops
  @base_iv = base_iv
end

Instance Attribute Details

#algObject

Returns the value of attribute alg.



30
31
32
# File 'lib/cose/key/base.rb', line 30

def alg
  @alg
end

#base_ivObject

Returns the value of attribute base_iv.



30
31
32
# File 'lib/cose/key/base.rb', line 30

def base_iv
  @base_iv
end

#key_opsObject

Returns the value of attribute key_ops.



30
31
32
# File 'lib/cose/key/base.rb', line 30

def key_ops
  @key_ops
end

#kidObject

Returns the value of attribute kid.



30
31
32
# File 'lib/cose/key/base.rb', line 30

def kid
  @kid
end

Class Method Details

.deserialize(cbor) ⇒ Object



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

def self.deserialize(cbor)
  from_map(CBOR.decode(cbor))
end

.from_map(map) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cose/key/base.rb', line 18

def self.from_map(map)
  enforce_type(map)

  new(
    base_iv: map[LABEL_BASE_IV],
    key_ops: map[LABEL_KEY_OPS],
    alg: map[LABEL_ALG],
    kid: map[LABEL_KID],
    **keyword_arguments_for_initialize(map)
  )
end

Instance Method Details

#mapObject



43
44
45
46
47
48
49
50
# File 'lib/cose/key/base.rb', line 43

def map
  {
    LABEL_BASE_IV => base_iv,
    LABEL_KEY_OPS => key_ops,
    LABEL_ALG => alg,
    LABEL_KID => kid,
  }.compact
end

#serializeObject



39
40
41
# File 'lib/cose/key/base.rb', line 39

def serialize
  CBOR.encode(map)
end