Class: COSE::Key::RSA
Constant Summary collapse
- N =
-1
- E =
-2
- D =
-3
- P =
-4
- Q =
-5
- DP =
-6
- DQ =
-7
- QI =
-8
- ALGS =
{ 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
-
#d ⇒ Object
Returns the value of attribute d.
-
#dp ⇒ Object
Returns the value of attribute dp.
-
#dq ⇒ Object
Returns the value of attribute dq.
-
#e ⇒ Object
Returns the value of attribute e.
-
#n ⇒ Object
Returns the value of attribute n.
-
#p ⇒ Object
Returns the value of attribute p.
-
#q ⇒ Object
Returns the value of attribute q.
-
#qi ⇒ Object
Returns the value of attribute qi.
Attributes inherited from COSE::Key
#alg, #base_iv, #kid, #kty, #ops, #raw
Instance Method Summary collapse
- #alg_key ⇒ Object
- #digest ⇒ Object
-
#initialize(attrs = {}) ⇒ RSA
constructor
A new instance of RSA.
- #to_key ⇒ Object
- #verify(signature, signature_base_string) ⇒ Object
Methods inherited from COSE::Key
Constructor Details
#initialize(attrs = {}) ⇒ RSA
Returns a new instance of RSA.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cose/key/rsa.rb', line 24 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
#d ⇒ Object
Returns the value of attribute d.
22 23 24 |
# File 'lib/cose/key/rsa.rb', line 22 def d @d end |
#dp ⇒ Object
Returns the value of attribute dp.
22 23 24 |
# File 'lib/cose/key/rsa.rb', line 22 def dp @dp end |
#dq ⇒ Object
Returns the value of attribute dq.
22 23 24 |
# File 'lib/cose/key/rsa.rb', line 22 def dq @dq end |
#e ⇒ Object
Returns the value of attribute e.
22 23 24 |
# File 'lib/cose/key/rsa.rb', line 22 def e @e end |
#n ⇒ Object
Returns the value of attribute n.
22 23 24 |
# File 'lib/cose/key/rsa.rb', line 22 def n @n end |
#p ⇒ Object
Returns the value of attribute p.
22 23 24 |
# File 'lib/cose/key/rsa.rb', line 22 def p @p end |
#q ⇒ Object
Returns the value of attribute q.
22 23 24 |
# File 'lib/cose/key/rsa.rb', line 22 def q @q end |
#qi ⇒ Object
Returns the value of attribute qi.
22 23 24 |
# File 'lib/cose/key/rsa.rb', line 22 def qi @qi end |
Instance Method Details
#alg_key ⇒ Object
36 37 38 39 |
# File 'lib/cose/key/rsa.rb', line 36 def alg_key ALGS.invert[alg] or raise UknownAlgorithm, 'Unknown Algorithm' end |
#digest ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cose/key/rsa.rb', line 41 def digest case alg_key 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 end.new end |
#to_key ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cose/key/rsa.rb', line 54 def to_key # Public key data_sequence = OpenSSL::ASN1::Sequence([ OpenSSL::ASN1::Integer(n), OpenSSL::ASN1::Integer(e), ]) if d && p && q && dp && dq && qi data_sequence = OpenSSL::ASN1::Sequence([ OpenSSL::ASN1::Integer(0), OpenSSL::ASN1::Integer(n), OpenSSL::ASN1::Integer(e), OpenSSL::ASN1::Integer(d), OpenSSL::ASN1::Integer(p), OpenSSL::ASN1::Integer(q), OpenSSL::ASN1::Integer(dp), OpenSSL::ASN1::Integer(dq), OpenSSL::ASN1::Integer(qi), ]) end asn1 = OpenSSL::ASN1::Sequence(data_sequence) OpenSSL::PKey::RSA.new(asn1.to_der) 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 |
#verify(signature, signature_base_string) ⇒ Object
95 96 97 |
# File 'lib/cose/key/rsa.rb', line 95 def verify(signature, signature_base_string) to_key.verify_pss digest, signature, signature_base_string end |