summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorthekuwayama <thekuwayama@gmail.com>2019-06-20 19:31:01 +0900
committerthekuwayama <thekuwayama@gmail.com>2019-06-20 19:31:01 +0900
commit87953b640e359d2f9213dfba24af773ce06fec4f (patch)
treef7f91dd342dd7da7a0bc8a3c8f4502e67d23f383 /test
parent1c7181d20003533fbe53f9505245812ae1646708 (diff)
downloadruby-openssl-87953b640e359d2f9213dfba24af773ce06fec4f.tar.gz
fix RSA#export and RSA#to_der to check key, factors and crt_params
Diffstat (limited to 'test')
-rw-r--r--test/test_pkey_rsa.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/test_pkey_rsa.rb b/test/test_pkey_rsa.rb
index c70be998..58558daa 100644
--- a/test/test_pkey_rsa.rb
+++ b/test/test_pkey_rsa.rb
@@ -171,6 +171,40 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
}
end
+ def test_export
+ rsa1024 = Fixtures.pkey("rsa1024")
+ key = OpenSSL::PKey::RSA.new
+
+ # key has only n, e and d
+ key.set_key(rsa1024.n, rsa1024.e, rsa1024.d)
+ assert_equal rsa1024.public_key.export, key.export
+
+ # key has only n, e, d, p and q
+ key.set_factors(rsa1024.p, rsa1024.q)
+ assert_equal rsa1024.public_key.export, key.export
+
+ # key has n, e, d, p, q, dmp1, dmq1 and iqmp
+ key.set_crt_params(rsa1024.dmp1, rsa1024.dmq1, rsa1024.iqmp)
+ assert_equal rsa1024.export, key.export
+ end
+
+ def test_to_der
+ rsa1024 = Fixtures.pkey("rsa1024")
+ key = OpenSSL::PKey::RSA.new
+
+ # key has only n, e and d
+ key.set_key(rsa1024.n, rsa1024.e, rsa1024.d)
+ assert_equal rsa1024.public_key.to_der, key.to_der
+
+ # key has only n, e, d, p and q
+ key.set_factors(rsa1024.p, rsa1024.q)
+ assert_equal rsa1024.public_key.to_der, key.to_der
+
+ # key has n, e, d, p, q, dmp1, dmq1 and iqmp
+ key.set_crt_params(rsa1024.dmp1, rsa1024.dmq1, rsa1024.iqmp)
+ assert_equal rsa1024.to_der, key.to_der
+ end
+
def test_RSAPrivateKey
rsa1024 = Fixtures.pkey("rsa1024")
asn1 = OpenSSL::ASN1::Sequence([