зеркало из https://github.com/github/ruby.git
* ext/openssl/ossl_digest.c: allow Digests to be created by sn, ln or
oid. * test/openssl/test_digest.rb: add tests for this. [Ruby 1.9 - Feature #4412] [ruby-core:35319] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a27b63d3fc
Коммит
4247bfd60a
|
@ -1,3 +1,10 @@
|
|||
Mon Jun 13 11:30:10 2011 Martin Bosslet <Martin.Bosslet@googlemail.com>
|
||||
|
||||
* ext/openssl/ossl_digest.c: allow Digests to be created by sn, ln or
|
||||
oid.
|
||||
* test/openssl/test_digest.rb: add tests for this.
|
||||
[Ruby 1.9 - Feature #4412] [ruby-core:35319]
|
||||
|
||||
Mon Jun 13 10:54:03 2011 Martin Bosslet <Martin.Bosslet@googlemail.com>
|
||||
|
||||
* ext/openssl/pkey_dh.c: corrected documentation.
|
||||
|
|
|
@ -36,12 +36,15 @@ const EVP_MD *
|
|||
GetDigestPtr(VALUE obj)
|
||||
{
|
||||
const EVP_MD *md;
|
||||
ASN1_OBJECT *oid = NULL;
|
||||
|
||||
if (TYPE(obj) == T_STRING) {
|
||||
const char *name = StringValueCStr(obj);
|
||||
|
||||
md = EVP_get_digestbyname(name);
|
||||
if (!md)
|
||||
oid = OBJ_txt2obj(name, 0);
|
||||
md = EVP_get_digestbyobj(oid);
|
||||
ASN1_OBJECT_free(oid);
|
||||
if(!md)
|
||||
ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
|
||||
} else {
|
||||
EVP_MD_CTX *ctx;
|
||||
|
@ -260,8 +263,9 @@ ossl_digest_size(VALUE self)
|
|||
* digest.block_length -> integer
|
||||
*
|
||||
* Returns the block length of the digest algorithm, i.e. the length in bytes
|
||||
* of an individual block. Most modern partition a message to be digested into
|
||||
* a sequence of fix-sized blocks that are processed consecutively.
|
||||
* of an individual block. Most modern algorithms partition a message to be
|
||||
* digested into a sequence of fix-sized blocks that are processed
|
||||
* consecutively.
|
||||
*
|
||||
* === Example
|
||||
* digest = OpenSSL::Digest::SHA1.new
|
||||
|
|
|
@ -56,6 +56,11 @@ class OpenSSL::TestDigest < Test::Unit::TestCase
|
|||
assert_equal(dig1, dig2, "reset")
|
||||
end
|
||||
|
||||
def test_digest_by_oid_and_name
|
||||
check_digest(OpenSSL::ASN1::ObjectId.new("MD5"))
|
||||
check_digest(OpenSSL::ASN1::ObjectId.new("SHA1"))
|
||||
end
|
||||
|
||||
if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00908000
|
||||
def encode16(str)
|
||||
str.unpack("H*").first
|
||||
|
@ -77,6 +82,24 @@ class OpenSSL::TestDigest < Test::Unit::TestCase
|
|||
assert_equal(sha384_a, encode16(OpenSSL::Digest::SHA384.digest("a")))
|
||||
assert_equal(sha512_a, encode16(OpenSSL::Digest::SHA512.digest("a")))
|
||||
end
|
||||
|
||||
def test_digest_by_oid_and_name_sha2
|
||||
check_digest(OpenSSL::ASN1::ObjectId.new("SHA224"))
|
||||
check_digest(OpenSSL::ASN1::ObjectId.new("SHA256"))
|
||||
check_digest(OpenSSL::ASN1::ObjectId.new("SHA384"))
|
||||
check_digest(OpenSSL::ASN1::ObjectId.new("SHA512"))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_digest(oid)
|
||||
d = OpenSSL::Digest.new(oid.sn)
|
||||
assert_not_nil(d)
|
||||
d = OpenSSL::Digest.new(oid.ln)
|
||||
assert_not_nil(d)
|
||||
d = OpenSSL::Digest.new(oid.oid)
|
||||
assert_not_nil(d)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче