Class: COSE::Key::CurveKey

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

Direct Known Subclasses

EC2, OKP

Constant Summary collapse

LABEL_CRV =
-1
LABEL_X =
-2
LABEL_D =
-4

Constants inherited from Base

Base::LABEL_ALG, Base::LABEL_BASE_IV, Base::LABEL_KEY_OPS, Base::LABEL_KID, Base::LABEL_KTY

Instance Attribute Summary collapse

Attributes inherited from Base

#alg, #base_iv, #key_ops, #kid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

deserialize, from_map, #serialize

Constructor Details

#initialize(crv:, x: nil, d: nil, **keyword_arguments) ⇒ CurveKey

rubocop:disable Naming/MethodParameterName



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cose/key/curve_key.rb', line 23

def initialize(crv:, x: nil, d: nil, **keyword_arguments) # rubocop:disable Naming/MethodParameterName
  super(**keyword_arguments)

  if !crv
    raise ArgumentError, "Required crv is missing"
  elsif !x && !d
    raise ArgumentError, "x and d cannot be missing simultaneously"
  else
    @crv = crv
    @x = x
    @d = d
  end
end

Instance Attribute Details

#crvObject (readonly)

Returns the value of attribute crv.



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

def crv
  @crv
end

#dObject (readonly)

Returns the value of attribute d.



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

def d
  @d
end

#xObject (readonly)

Returns the value of attribute x.



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

def x
  @x
end

Class Method Details

.keyword_arguments_for_initialize(map) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/cose/key/curve_key.rb', line 15

def self.keyword_arguments_for_initialize(map)
  {
    crv: map[LABEL_CRV],
    x: map[LABEL_X],
    d: map[LABEL_D]
  }
end

Instance Method Details

#mapObject



37
38
39
40
41
42
43
# File 'lib/cose/key/curve_key.rb', line 37

def map
  super.merge(
    LABEL_CRV => crv,
    LABEL_X => x,
    LABEL_D => d
  ).compact
end