diff options
author | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-29 05:47:09 +0000 |
---|---|---|
committer | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-29 05:47:09 +0000 |
commit | 86048989b2460d1dd762037449f8c9a9f6d35d3a (patch) | |
tree | 831281099f54c0be80293785761a46688a0711f3 /test/openssl/test_pkey.rb | |
parent | 796285b70303b376244d9b526113face212f230c (diff) | |
download | ruby-86048989b2460d1dd762037449f8c9a9f6d35d3a.tar.gz |
import Ruby/OpenSSL 2.0.0.beta.1
* NEWS, {ext,test,sample}/openssl: Import Ruby/OpenSSL 2.0.0.beta.1.
ext/openssl is now converted into a default gem. The full commit
history since r55538 can be found at:
https://github.com/ruby/openssl/compare/08e1881f5663...v2.0.0.beta.1
[Feature #9612]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/openssl/test_pkey.rb')
-rw-r--r-- | test/openssl/test_pkey.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/openssl/test_pkey.rb b/test/openssl/test_pkey.rb new file mode 100644 index 0000000000..79647c8f1d --- /dev/null +++ b/test/openssl/test_pkey.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: false +require_relative "utils" + +if defined?(OpenSSL::TestUtils) + +class OpenSSL::TestPKey < OpenSSL::PKeyTestCase + PKEYS = { + OpenSSL::PKey::RSA => { + key: OpenSSL::TestUtils::TEST_KEY_RSA1024, + digest: OpenSSL::Digest::SHA1, + }, + OpenSSL::PKey::DSA => { + key: OpenSSL::TestUtils::TEST_KEY_DSA512, + digest: OpenSSL::TestUtils::DSA_SIGNATURE_DIGEST, + }, + } + if defined?(OpenSSL::PKey::EC) + PKEYS[OpenSSL::PKey::EC] = { + key: OpenSSL::TestUtils::TEST_KEY_EC_P256V1, + digest: OpenSSL::Digest::SHA1, + } + end + + def test_sign_verify + data = "Sign me!" + invalid_data = "Sign me?" + PKEYS.each do |klass, prop| + key = prop[:key] + pub_key = dup_public(prop[:key]) + digest = prop[:digest].new + signature = key.sign(digest, data) + assert_equal(true, pub_key.verify(digest, signature, data)) + assert_equal(false, pub_key.verify(digest, signature, invalid_data)) + # digest state is irrelevant + digest << "unya" + assert_equal(true, pub_key.verify(digest, signature, data)) + assert_equal(false, pub_key.verify(digest, signature, invalid_data)) + + if OpenSSL::OPENSSL_VERSION_NUMBER > 0x10000000 + digest = OpenSSL::Digest::SHA256.new + signature = key.sign(digest, data) + assert_equal(true, pub_key.verify(digest, signature, data)) + assert_equal(false, pub_key.verify(digest, signature, invalid_data)) + end + end + end +end + +end |