lib/cose/key/rsa.rb in cose-0.6.0 vs lib/cose/key/rsa.rb in cose-0.6.1

- old
+ new

@@ -98,23 +98,25 @@ pkey.n = bn(n) pkey.e = bn(e) pkey.d = bn(d) end - if pkey.respond_to?(:set_factors) - pkey.set_factors(bn(p), bn(q)) - else - pkey.p = bn(p) - pkey.q = bn(q) - end + if private? + if pkey.respond_to?(:set_factors) + pkey.set_factors(bn(p), bn(q)) + else + pkey.p = bn(p) + pkey.q = bn(q) + end - if pkey.respond_to?(:set_crt_params) - pkey.set_crt_params(bn(dp), bn(dq), bn(qinv)) - else - pkey.dmp1 = bn(dp) - pkey.dmq1 = bn(dq) - pkey.iqmp = bn(qinv) + if pkey.respond_to?(:set_crt_params) + pkey.set_crt_params(bn(dp), bn(dq), bn(qinv)) + else + pkey.dmp1 = bn(dp) + pkey.dmq1 = bn(dq) + pkey.iqmp = bn(qinv) + end end pkey end @@ -131,11 +133,17 @@ } end private + def private? + [d, p, q, dp, dq, qinv].none?(&:nil?) + end + def bn(data) - OpenSSL::BN.new(data, 2) + if data + OpenSSL::BN.new(data, 2) + end end end end end