* ext/digest/digest.c (rb_digest_instance_hexdigest_bang): Fix
rdoc. * ext/digest/lib/digest.rb (Digest::Class.base64digest) (Digest::Instance#base64digest{,!}): New methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7bfdad3b62
commit
d8f265b332
@ -1,3 +1,11 @@
|
|||||||
|
Mon Jan 18 03:59:57 2010 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* ext/digest/digest.c (rb_digest_instance_hexdigest_bang): Fix
|
||||||
|
rdoc.
|
||||||
|
|
||||||
|
* ext/digest/lib/digest.rb (Digest::Class.base64digest)
|
||||||
|
(Digest::Instance#base64digest{,!}): New methods.
|
||||||
|
|
||||||
Sun Jan 17 22:48:44 2010 Akinori MUSHA <knu@iDaemons.org>
|
Sun Jan 17 22:48:44 2010 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* ext/digest/digest.c (rb_digest_instance_digest)
|
* ext/digest/digest.c (rb_digest_instance_digest)
|
||||||
|
6
NEWS
6
NEWS
@ -114,6 +114,12 @@ with all sufficient information, see the ChangeLog file.
|
|||||||
* respond_to? can be used to detect methods not implemented.
|
* respond_to? can be used to detect methods not implemented.
|
||||||
For example, Process.respond_to?(:fork) returns false on Windows.
|
For example, Process.respond_to?(:fork) returns false on Windows.
|
||||||
|
|
||||||
|
* digest
|
||||||
|
* new methods:
|
||||||
|
* Digest::Class.base64digest
|
||||||
|
* Digest::Instance#base64digest
|
||||||
|
* Digest::Instance#base64digest!
|
||||||
|
|
||||||
* rss
|
* rss
|
||||||
|
|
||||||
* 0.2.4 -> 0.2.7.
|
* 0.2.4 -> 0.2.7.
|
||||||
|
@ -234,8 +234,8 @@ rb_digest_instance_hexdigest(int argc, VALUE *argv, VALUE self)
|
|||||||
* call-seq:
|
* call-seq:
|
||||||
* digest_obj.hexdigest! -> string
|
* digest_obj.hexdigest! -> string
|
||||||
*
|
*
|
||||||
* Returns the resulting hash value and resets the digest to the
|
* Returns the resulting hash value in a hex-encoded form and resets
|
||||||
* initial state.
|
* the digest to the initial state.
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_digest_instance_hexdigest_bang(VALUE self)
|
rb_digest_instance_hexdigest_bang(VALUE self)
|
||||||
|
@ -28,6 +28,13 @@ module Digest
|
|||||||
def self.file(name)
|
def self.file(name)
|
||||||
new.file(name)
|
new.file(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the base64 encoded hash value of a given _string_. The
|
||||||
|
# return value is properly padded with '=' and contains no line
|
||||||
|
# feeds.
|
||||||
|
def self.base64digest(str, *args)
|
||||||
|
[digest(str, *args)].pack('m0')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Instance
|
module Instance
|
||||||
@ -42,6 +49,25 @@ module Digest
|
|||||||
}
|
}
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If none is given, returns the resulting hash value of the digest
|
||||||
|
# in a base64 encoded form, keeping the digest's state.
|
||||||
|
#
|
||||||
|
# If a _string_ is given, returns the hash value for the given
|
||||||
|
# _string_ in a base64 encoded form, resetting the digest to the
|
||||||
|
# initial state before and after the process.
|
||||||
|
#
|
||||||
|
# In either case, the return value is properly padded with '=' and
|
||||||
|
# contains no line feeds.
|
||||||
|
def base64digest(str = nil)
|
||||||
|
[str ? digest(str) : digest].pack('m0')
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the resulting hash value and resets the digest to the
|
||||||
|
# initial state.
|
||||||
|
def base64digest!
|
||||||
|
[digest!].pack('m0')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,14 +18,22 @@ module TestDigest
|
|||||||
Data2 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
Data2 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||||
|
|
||||||
def test_s_hexdigest
|
def test_s_hexdigest
|
||||||
self.class::DATA.each do |str, digest|
|
self.class::DATA.each do |str, hexdigest|
|
||||||
assert_equal(digest, self.class::ALGO.hexdigest(str))
|
assert_equal(hexdigest, self.class::ALGO.hexdigest(str))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_s_base64digest
|
||||||
|
self.class::DATA.each do |str, hexdigest|
|
||||||
|
digest = [hexdigest].pack("H*")
|
||||||
|
assert_equal([digest].pack("m0"), self.class::ALGO.base64digest(str))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_s_digest
|
def test_s_digest
|
||||||
self.class::DATA.each do |str, digest|
|
self.class::DATA.each do |str, hexdigest|
|
||||||
assert_equal([digest].pack("H*"), self.class::ALGO.digest(str))
|
digest = [hexdigest].pack("H*")
|
||||||
|
assert_equal(digest, self.class::ALGO.digest(str))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user