Class: COSE::Key::RSA

Inherits:
COSE::Key show all
Defined in:
lib/cose/key/rsa.rb

Constant Summary collapse

N =
-1
E =
-2
D =
-3
P =
-4
Q =
-5
DP =
-6
DQ =
-7
QI =
-8
PS256 =
-37
PS384 =
-38
PS512 =
-39
RSAES_OAEP_SHA1 =
-40
RSAES_OAEP_SHA256 =
-41
RSAES_OAEP_SHA512 =
-42

Constants inherited from COSE::Key

ALG, BASE_IV, KID, KTY, KTY_EC2, KTY_OKP, KTY_RSA, KTY_SYMMETRIC, OPS

Instance Attribute Summary collapse

Attributes inherited from COSE::Key

#alg, #base_iv, #kid, #kty, #ops, #raw

Instance Method Summary collapse

Methods inherited from COSE::Key

decode, detect, #to_pem, #to_s, #to_text

Constructor Details

#initialize(attrs = {}) ⇒ RSA

Returns a new instance of RSA.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cose/key/rsa.rb', line 22

def initialize(attrs = {})
  super
  self.n = attrs[N]
  self.e = attrs[E]
  self.d = attrs[D]
  self.p = attrs[P]
  self.q = attrs[Q]
  self.dp = attrs[DP]
  self.dq = attrs[DQ]
  self.qi = attrs[QI]
end

Instance Attribute Details

#dObject

Returns the value of attribute d.



20
21
22
# File 'lib/cose/key/rsa.rb', line 20

def d
  @d
end

#dpObject

Returns the value of attribute dp.



20
21
22
# File 'lib/cose/key/rsa.rb', line 20

def dp
  @dp
end

#dqObject

Returns the value of attribute dq.



20
21
22
# File 'lib/cose/key/rsa.rb', line 20

def dq
  @dq
end

#eObject

Returns the value of attribute e.



20
21
22
# File 'lib/cose/key/rsa.rb', line 20

def e
  @e
end

#nObject

Returns the value of attribute n.



20
21
22
# File 'lib/cose/key/rsa.rb', line 20

def n
  @n
end

#pObject

Returns the value of attribute p.



20
21
22
# File 'lib/cose/key/rsa.rb', line 20

def p
  @p
end

#qObject

Returns the value of attribute q.



20
21
22
# File 'lib/cose/key/rsa.rb', line 20

def q
  @q
end

#qiObject

Returns the value of attribute qi.



20
21
22
# File 'lib/cose/key/rsa.rb', line 20

def qi
  @qi
end

Instance Method Details

#digestObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cose/key/rsa.rb', line 34

def digest
  case alg
  when RSAES_OAEP_SHA1
    OpenSSL::Digest::SHA1
  when PS256, RSAES_OAEP_SHA256
    OpenSSL::Digest::SHA256
  when PS384
    OpenSSL::Digest::SHA384
  when PS512, RSAES_OAEP_SHA512
    OpenSSL::Digest::SHA512
  else
    raise 'Unknown Algorithm'
  end.new
end

#to_keyObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cose/key/rsa.rb', line 49

def to_key
  key = OpenSSL::PKey::RSA.new
  if key.respond_to? :set_key
    key.set_key n, e, d
    key.set_factors p, q if p && q
    key.set_crt_params dp, dq, qi if dp && dq && qi
  else
    key.e = e
    key.n = n
    key.d = d if d
    key.p = p if p
    key.q = q if q
    key.dmp1 = dp if dp
    key.dmq1 = dq if dq
    key.iqmp = qi if qi
  end
  key
end