* test/openssl/test_pkey_dsa.rb: Add tests for sign/verify.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
emboss 2011-05-21 22:13:27 +00:00
Родитель ee02506321
Коммит affb9cfbc8
2 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Sun May 22 07:10:25 2011 Martin Bosslet <Martin.Bosslet@googlemail.com>
* test/openssl/test_pkey_dsa.rb: Add tests for sign/verify.
Sun May 22 06:07:17 2011 Martin Bosslet <Martin.Bosslet@googlemail.com>
* test/openssl/test_x509cert.rb: Merge DSA-related tests from ruby_1_8

Просмотреть файл

@ -22,6 +22,32 @@ class OpenSSL::TestPKeyDSA < Test::Unit::TestCase
assert_equal([], OpenSSL.errors)
end
def test_sign_verify
check_sign_verify(OpenSSL::Digest::DSS1.new)
end
if (OpenSSL::OPENSSL_VERSION_NUMBER > 0x10000000)
def test_sign_verify_sha1
check_sign_verify(OpenSSL::Digest::SHA1.new)
end
def test_sign_verify_sha256
check_sign_verify(OpenSSL::Digest::SHA256.new)
end
end
def test_digest_state_irrelevant_verify
key = OpenSSL::PKey::DSA.new(256)
digest1 = OpenSSL::Digest::DSS1.new
digest2 = OpenSSL::Digest::DSS1.new
data = 'Sign me!'
sig = key.sign(digest1, data)
digest1.reset
digest1 << 'Change state of digest1'
assert(key.verify(digest1, sig, data))
assert(key.verify(digest2, sig, data))
end
def test_read_DSA_PUBKEY
p = 7188211954100152441468596248707152960171255279130004340103875772401008316444412091945435731597638374542374929457672178957081124632837356913990200866056699
q = 957032439192465935099784319494405376402293318491
@ -121,6 +147,15 @@ YNMbNw==
assert_equal(OpenSSL::ASN1::INTEGER, pub_key.tag)
assert_equal(key.pub_key, pub_key.value)
end
private
def check_sign_verify(digest)
key = OpenSSL::PKey::DSA.new(256)
data = 'Sign me!'
sig = key.sign(digest, data)
assert(key.verify(digest, sig, data))
end
end
end