Class: COSE::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/cose/key.rb,
lib/cose/key/ec2.rb,
lib/cose/key/rsa.rb

Direct Known Subclasses

EC2, RSA

Defined Under Namespace

Classes: EC2, RSA

Constant Summary collapse

KTY =
1
KID =
2
ALG =
3
OPS =
4
BASE_IV =
5
KTY_OKP =
1
KTY_EC2 =
2
KTY_RSA =
3
KTY_SYMMETRIC =
4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Key

Returns a new instance of Key.



19
20
21
22
23
24
25
# File 'lib/cose/key.rb', line 19

def initialize(attrs = {})
  self.kty = attrs[KTY]
  self.kid = attrs[KID]
  self.alg = attrs[ALG]
  self.ops = attrs[OPS]
  self.base_iv = attrs[BASE_IV]
end

Instance Attribute Details

#algObject

Returns the value of attribute alg.



17
18
19
# File 'lib/cose/key.rb', line 17

def alg
  @alg
end

#base_ivObject

Returns the value of attribute base_iv.



17
18
19
# File 'lib/cose/key.rb', line 17

def base_iv
  @base_iv
end

#kidObject

Returns the value of attribute kid.



17
18
19
# File 'lib/cose/key.rb', line 17

def kid
  @kid
end

#ktyObject

Returns the value of attribute kty.



17
18
19
# File 'lib/cose/key.rb', line 17

def kty
  @kty
end

#opsObject

Returns the value of attribute ops.



17
18
19
# File 'lib/cose/key.rb', line 17

def ops
  @ops
end

#rawObject

Returns the value of attribute raw.



17
18
19
# File 'lib/cose/key.rb', line 17

def raw
  @raw
end

Class Method Details

.decode(cbor) ⇒ Object



48
49
50
51
52
# File 'lib/cose/key.rb', line 48

def decode(cbor)
  key = detect CBOR.decode(cbor)
  key.raw = cbor
  key
end

.detect(attrs = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cose/key.rb', line 54

def detect(attrs = {})
  klass = case attrs[KTY]
  when KTY_OKP
    raise 'Unsupported Key Type: OKP'
  when KTY_EC2
    EC2
  when KTY_RSA
    RSA
  when KTY_SYMMETRIC
    raise 'Unsupported Key Type: Symmetric'
  else
    raise 'Unknown Key Type'
  end
  klass.new attrs
end

Instance Method Details

#digestObject



27
28
29
# File 'lib/cose/key.rb', line 27

def digest
  raise 'Implement me'
end

#to_keyObject



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

def to_key
  raise 'Implement me'
end

#to_pemObject



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

def to_pem
  to_key.to_pem
end

#to_sObject



35
36
37
# File 'lib/cose/key.rb', line 35

def to_s
  raw
end

#to_textObject



43
44
45
# File 'lib/cose/key.rb', line 43

def to_text
  to_key.to_text
end