summaryrefslogtreecommitdiff
path: root/ext/digest/lib/digest.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-17 19:12:10 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-17 19:12:10 +0000
commitd8f265b332506dcb7b9738247f0d895e51477ea6 (patch)
treef6d7b1b56021a7e518be15d2da9b3a84ad1b2999 /ext/digest/lib/digest.rb
parent7bfdad3b62eb19c216baed90d4da5c6a6545fe8c (diff)
* 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
Diffstat (limited to 'ext/digest/lib/digest.rb')
-rw-r--r--ext/digest/lib/digest.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb
index e42f984f95..857501722e 100644
--- a/ext/digest/lib/digest.rb
+++ b/ext/digest/lib/digest.rb
@@ -28,6 +28,13 @@ module Digest
def self.file(name)
new.file(name)
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
module Instance
@@ -42,6 +49,25 @@ module Digest
}
self
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