class COSE::Key::RSA

Constants

ALGS
D
DP
DQ
E
N
P
Q
QI

Attributes

d[RW]
dp[RW]
dq[RW]
e[RW]
n[RW]
p[RW]
q[RW]
qi[RW]

Public Class Methods

new(attrs = {}) click to toggle source
Calls superclass method COSE::Key::new
# 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

Public Instance Methods

alg_key() click to toggle source
# File lib/cose/key/rsa.rb, line 36
def alg_key
  ALGS.invert[alg] or
  raise UknownAlgorithm, 'Unknown Algorithm'
end
digest() click to toggle source
# 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() click to toggle source
# File lib/cose/key/rsa.rb, line 54
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
verify(signature, signature_base_string) click to toggle source
# File lib/cose/key/rsa.rb, line 73
def verify(signature, signature_base_string)
  to_key.verify_pss digest, signature, signature_base_string
end