2001-07-13 16:06:14 -04:00
|
|
|
/************************************************
|
|
|
|
|
|
|
|
digest.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Fri May 25 08:57:27 JST 2001
|
|
|
|
|
|
|
|
Copyright (C) 1995-2001 Yukihiro Matsumoto
|
2006-10-05 15:13:00 -04:00
|
|
|
Copyright (C) 2001-2006 Akinori MUSHA
|
2001-07-13 16:06:14 -04:00
|
|
|
|
|
|
|
$RoughId: digest.c,v 1.16 2001/07/13 15:38:27 knu Exp $
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
|
|
#include "digest.h"
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
static VALUE rb_mDigest;
|
|
|
|
static VALUE rb_mDigest_Instance;
|
|
|
|
static VALUE rb_cDigest_Class;
|
|
|
|
static VALUE rb_cDigest_Base;
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
static ID id_reset, id_update, id_finish, id_digest, id_hexdigest, id_digest_length;
|
|
|
|
static ID id_metadata;
|
|
|
|
|
|
|
|
RUBY_EXTERN void Init_digest_base(void);
|
2006-10-13 07:52:18 -04:00
|
|
|
|
|
|
|
/*
|
2006-10-20 08:48:35 -04:00
|
|
|
* Document-module: Digest
|
2006-10-13 07:52:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* This module provides a framework for message digest libraries.
|
2001-07-13 16:06:14 -04:00
|
|
|
*/
|
|
|
|
|
* ext/digest/digest.[ch]: Since the argument order of
hash_final_func_t was inconsistent with others, change it and
rename to hash_finish_func_t to avoid confusion.
* ext/digest/digest.[ch]: Remove and eliminate the use of
hash_end_func_t. Implement hexdigest conversion in the base
class.
* ext/digest/md5/md5.c, ext/digest/md5/md5.h,
ext/digest/md5/md5init.c, ext/digest/md5/md5ossl.c,
ext/digest/md5/md5ossl.h: Remove MD5_End() and change
MD5_Final() to MD5_Finish().
* ext/digest/rmd160/depend, ext/digest/rmd160/extconf.rb,
ext/digest/rmd160/rmd160.c, ext/digest/rmd160/rmd160.h,
ext/digest/rmd160/rmd160hl.c, ext/digest/rmd160/rmd160init.c,
ext/digest/rmd160/rmd160ossl.c, ext/digest/rmd160/rmd160ossl.h:
Remove unused functions RMD160_End(), RMD160_File(),
RMD160_Data() and change RMD160_Final() to RMD160_Finish().
* ext/digest/sha1/extconf.rb, ext/digest/sha1/sha1.c,
ext/digest/sha1/sha1.h, ext/digest/sha1/sha1hl.c,
ext/digest/sha1/sha1init.c, ext/digest/sha1/sha1ossl.c,
ext/digest/sha1/sha1ossl.h: Likewise.
* ext/digest/sha2/extconf.rb, ext/digest/sha2/sha2.c,
ext/digest/sha2/sha2.h, ext/digest/sha2/sha2hl.c,
ext/digest/sha2/sha2init.c: Likewise.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-05 07:09:42 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
hexencode_str_new(VALUE str_digest)
|
* ext/digest/digest.[ch]: Since the argument order of
hash_final_func_t was inconsistent with others, change it and
rename to hash_finish_func_t to avoid confusion.
* ext/digest/digest.[ch]: Remove and eliminate the use of
hash_end_func_t. Implement hexdigest conversion in the base
class.
* ext/digest/md5/md5.c, ext/digest/md5/md5.h,
ext/digest/md5/md5init.c, ext/digest/md5/md5ossl.c,
ext/digest/md5/md5ossl.h: Remove MD5_End() and change
MD5_Final() to MD5_Finish().
* ext/digest/rmd160/depend, ext/digest/rmd160/extconf.rb,
ext/digest/rmd160/rmd160.c, ext/digest/rmd160/rmd160.h,
ext/digest/rmd160/rmd160hl.c, ext/digest/rmd160/rmd160init.c,
ext/digest/rmd160/rmd160ossl.c, ext/digest/rmd160/rmd160ossl.h:
Remove unused functions RMD160_End(), RMD160_File(),
RMD160_Data() and change RMD160_Final() to RMD160_Finish().
* ext/digest/sha1/extconf.rb, ext/digest/sha1/sha1.c,
ext/digest/sha1/sha1.h, ext/digest/sha1/sha1hl.c,
ext/digest/sha1/sha1init.c, ext/digest/sha1/sha1ossl.c,
ext/digest/sha1/sha1ossl.h: Likewise.
* ext/digest/sha2/extconf.rb, ext/digest/sha2/sha2.c,
ext/digest/sha2/sha2.h, ext/digest/sha2/sha2hl.c,
ext/digest/sha2/sha2init.c: Likewise.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-05 07:09:42 -04:00
|
|
|
{
|
2006-10-10 03:49:00 -04:00
|
|
|
char *digest;
|
|
|
|
size_t digest_len;
|
* ext/digest/digest.[ch]: Since the argument order of
hash_final_func_t was inconsistent with others, change it and
rename to hash_finish_func_t to avoid confusion.
* ext/digest/digest.[ch]: Remove and eliminate the use of
hash_end_func_t. Implement hexdigest conversion in the base
class.
* ext/digest/md5/md5.c, ext/digest/md5/md5.h,
ext/digest/md5/md5init.c, ext/digest/md5/md5ossl.c,
ext/digest/md5/md5ossl.h: Remove MD5_End() and change
MD5_Final() to MD5_Finish().
* ext/digest/rmd160/depend, ext/digest/rmd160/extconf.rb,
ext/digest/rmd160/rmd160.c, ext/digest/rmd160/rmd160.h,
ext/digest/rmd160/rmd160hl.c, ext/digest/rmd160/rmd160init.c,
ext/digest/rmd160/rmd160ossl.c, ext/digest/rmd160/rmd160ossl.h:
Remove unused functions RMD160_End(), RMD160_File(),
RMD160_Data() and change RMD160_Final() to RMD160_Finish().
* ext/digest/sha1/extconf.rb, ext/digest/sha1/sha1.c,
ext/digest/sha1/sha1.h, ext/digest/sha1/sha1hl.c,
ext/digest/sha1/sha1init.c, ext/digest/sha1/sha1ossl.c,
ext/digest/sha1/sha1ossl.h: Likewise.
* ext/digest/sha2/extconf.rb, ext/digest/sha2/sha2.c,
ext/digest/sha2/sha2.h, ext/digest/sha2/sha2hl.c,
ext/digest/sha2/sha2init.c: Likewise.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-05 07:09:42 -04:00
|
|
|
int i;
|
|
|
|
VALUE str;
|
|
|
|
char *p;
|
2006-10-05 13:07:59 -04:00
|
|
|
static const char hex[] = {
|
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
|
|
'a', 'b', 'c', 'd', 'e', 'f'
|
|
|
|
};
|
|
|
|
|
2006-10-10 03:49:00 -04:00
|
|
|
StringValue(str_digest);
|
|
|
|
digest = RSTRING_PTR(str_digest);
|
|
|
|
digest_len = RSTRING_LEN(str_digest);
|
|
|
|
|
2006-10-05 13:07:59 -04:00
|
|
|
if (LONG_MAX / 2 < digest_len) {
|
|
|
|
rb_raise(rb_eRuntimeError, "digest string too long");
|
|
|
|
}
|
* ext/digest/digest.[ch]: Since the argument order of
hash_final_func_t was inconsistent with others, change it and
rename to hash_finish_func_t to avoid confusion.
* ext/digest/digest.[ch]: Remove and eliminate the use of
hash_end_func_t. Implement hexdigest conversion in the base
class.
* ext/digest/md5/md5.c, ext/digest/md5/md5.h,
ext/digest/md5/md5init.c, ext/digest/md5/md5ossl.c,
ext/digest/md5/md5ossl.h: Remove MD5_End() and change
MD5_Final() to MD5_Finish().
* ext/digest/rmd160/depend, ext/digest/rmd160/extconf.rb,
ext/digest/rmd160/rmd160.c, ext/digest/rmd160/rmd160.h,
ext/digest/rmd160/rmd160hl.c, ext/digest/rmd160/rmd160init.c,
ext/digest/rmd160/rmd160ossl.c, ext/digest/rmd160/rmd160ossl.h:
Remove unused functions RMD160_End(), RMD160_File(),
RMD160_Data() and change RMD160_Final() to RMD160_Finish().
* ext/digest/sha1/extconf.rb, ext/digest/sha1/sha1.c,
ext/digest/sha1/sha1.h, ext/digest/sha1/sha1hl.c,
ext/digest/sha1/sha1init.c, ext/digest/sha1/sha1ossl.c,
ext/digest/sha1/sha1ossl.h: Likewise.
* ext/digest/sha2/extconf.rb, ext/digest/sha2/sha2.c,
ext/digest/sha2/sha2.h, ext/digest/sha2/sha2hl.c,
ext/digest/sha2/sha2init.c: Likewise.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-05 07:09:42 -04:00
|
|
|
|
|
|
|
str = rb_str_new(0, digest_len * 2);
|
|
|
|
|
|
|
|
for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
|
|
|
|
unsigned char byte = digest[i];
|
|
|
|
|
|
|
|
p[i + i] = hex[byte >> 4];
|
|
|
|
p[i + i + 1] = hex[byte & 0x0f];
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Digest.hexencode(string) -> hexencoded_string
|
|
|
|
*
|
|
|
|
* Generates a hex-encoded version of a given _string_.
|
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_s_hexencode(VALUE klass, VALUE str)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
return hexencode_str_new(str);
|
|
|
|
}
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/*
|
|
|
|
* Document-module: Digest::Instance
|
|
|
|
*
|
|
|
|
* This module provides instance methods for a digest implementation
|
|
|
|
* object to calculate message digest values.
|
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.update(string) -> digest_obj
|
|
|
|
* digest_obj << string -> digest_obj
|
|
|
|
*
|
|
|
|
* Updates the digest using a given _string_ and returns self.
|
|
|
|
*
|
|
|
|
* The update() method and the left-shift operator are overridden by
|
|
|
|
* each implementation subclass. (One should be an alias for the
|
|
|
|
* other)
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_digest_instance_update(VALUE self, VALUE str)
|
|
|
|
{
|
2007-07-15 09:24:39 -04:00
|
|
|
rb_raise(rb_eRuntimeError, "%s does not implement update()", RSTRING_PTR(rb_inspect(self)));
|
2001-07-13 16:06:14 -04:00
|
|
|
}
|
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-20 08:48:35 -04:00
|
|
|
* digest_obj.instance_eval { finish } -> digest_obj
|
|
|
|
*
|
|
|
|
* Finishes the digest and returns the resulting hash value.
|
2006-10-13 07:52:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* This method is overridden by each implementation subclass and often
|
|
|
|
* made private, because some of those subclasses may leave internal
|
|
|
|
* data uninitialized. Do not call this method from outside. Use
|
|
|
|
* #digest!() instead, which ensures that internal data be reset for
|
|
|
|
* security reasons.
|
2006-10-13 07:52:18 -04:00
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_finish(VALUE self)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
2007-07-15 09:24:39 -04:00
|
|
|
rb_raise(rb_eRuntimeError, "%s does not implement finish()", RSTRING_PTR(rb_inspect(self)));
|
2001-07-13 16:06:14 -04:00
|
|
|
}
|
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-20 08:48:35 -04:00
|
|
|
* digest_obj.reset -> digest_obj
|
|
|
|
*
|
|
|
|
* Resets the digest to the initial state and returns self.
|
2006-10-13 07:52:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* This method is overridden by each implementation subclass.
|
2006-10-13 07:52:18 -04:00
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_reset(VALUE self)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
2007-07-15 09:24:39 -04:00
|
|
|
rb_raise(rb_eRuntimeError, "%s does not implement reset()", RSTRING_PTR(rb_inspect(self)));
|
2006-10-05 15:13:00 -04:00
|
|
|
}
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.new -> another_digest_obj
|
|
|
|
*
|
|
|
|
* Returns a new, initialized copy of the digest object. Equivalent
|
|
|
|
* to digest_obj.clone().reset().
|
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_new(VALUE self)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
VALUE clone = rb_obj_clone(self);
|
|
|
|
rb_funcall(clone, id_reset, 0);
|
|
|
|
return clone;
|
2001-07-13 16:06:14 -04:00
|
|
|
}
|
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-20 08:48:35 -04:00
|
|
|
* digest_obj.digest -> string
|
|
|
|
* digest_obj.digest(string) -> string
|
2006-10-13 07:52:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* If none is given, returns the resulting hash value of the digest,
|
|
|
|
* keeping the digest's state.
|
2006-10-13 16:55:33 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* If a _string_ is given, returns the hash value for the given
|
|
|
|
* _string_, resetting the digest to the initial state before and
|
|
|
|
* after the process.
|
2006-10-13 07:52:18 -04:00
|
|
|
*/
|
2006-10-11 01:15:15 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_digest(int argc, VALUE *argv, VALUE self)
|
2006-10-11 01:15:15 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
VALUE str, value;
|
2006-10-11 01:15:15 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
if (rb_scan_args(argc, argv, "01", &str) > 0) {
|
|
|
|
rb_funcall(self, id_reset, 0);
|
|
|
|
rb_funcall(self, id_update, 1, str);
|
|
|
|
value = rb_funcall(self, id_finish, 0);
|
|
|
|
rb_funcall(self, id_reset, 0);
|
|
|
|
} else {
|
|
|
|
VALUE clone = rb_obj_clone(self);
|
2006-10-11 01:15:15 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
value = rb_funcall(clone, id_finish, 0);
|
|
|
|
rb_funcall(clone, id_reset, 0);
|
2006-10-11 01:15:15 -04:00
|
|
|
}
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
return value;
|
2006-10-11 01:15:15 -04:00
|
|
|
}
|
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-20 08:48:35 -04:00
|
|
|
* digest_obj.digest! -> string
|
2006-10-13 16:55:33 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* Returns the resulting hash value and resets the digest to the
|
|
|
|
* initial state.
|
2006-10-13 07:52:18 -04:00
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_digest_bang(VALUE self)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
VALUE value = rb_funcall(self, id_finish, 0);
|
|
|
|
rb_funcall(self, id_reset, 0);
|
2006-10-05 13:39:51 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
return value;
|
2006-10-05 13:39:51 -04:00
|
|
|
}
|
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-20 08:48:35 -04:00
|
|
|
* digest_obj.hexdigest -> string
|
|
|
|
* digest_obj.hexdigest(string) -> string
|
2006-10-13 07:52:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* If none is given, returns the resulting hash value of the digest in
|
|
|
|
* a hex-encoded form, keeping the digest's state.
|
2006-10-13 16:55:33 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* If a _string_ is given, returns the hash value for the given
|
|
|
|
* _string_ in a hex-encoded form, resetting the digest to the initial
|
|
|
|
* state before and after the process.
|
2006-10-13 07:52:18 -04:00
|
|
|
*/
|
2006-10-05 13:39:51 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_hexdigest(int argc, VALUE *argv, VALUE self)
|
2006-10-05 13:39:51 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
VALUE str, value;
|
2006-10-05 13:39:51 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
if (rb_scan_args(argc, argv, "01", &str) > 0) {
|
|
|
|
rb_funcall(self, id_reset, 0);
|
2006-10-05 13:39:51 -04:00
|
|
|
rb_funcall(self, id_update, 1, str);
|
2006-10-20 08:48:35 -04:00
|
|
|
value = rb_funcall(self, id_finish, 0);
|
|
|
|
rb_funcall(self, id_reset, 0);
|
|
|
|
} else {
|
|
|
|
VALUE clone = rb_obj_clone(self);
|
2006-10-05 13:39:51 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
value = rb_funcall(clone, id_finish, 0);
|
|
|
|
rb_funcall(clone, id_reset, 0);
|
2006-10-05 13:39:51 -04:00
|
|
|
}
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
return hexencode_str_new(value);
|
2001-07-13 16:06:14 -04:00
|
|
|
}
|
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-20 08:48:35 -04:00
|
|
|
* digest_obj.hexdigest! -> string
|
2006-10-13 16:55:33 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* Returns the resulting hash value and resets the digest to the
|
|
|
|
* initial state.
|
2006-10-13 07:52:18 -04:00
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_hexdigest_bang(VALUE self)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
VALUE value = rb_funcall(self, id_finish, 0);
|
|
|
|
rb_funcall(self, id_reset, 0);
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
return hexencode_str_new(value);
|
2001-07-13 16:06:14 -04:00
|
|
|
}
|
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.to_s -> string
|
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* Returns digest_obj.hexdigest().
|
2006-10-13 07:52:18 -04:00
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_to_s(VALUE self)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
return rb_funcall(self, id_hexdigest, 0);
|
2006-10-05 15:13:00 -04:00
|
|
|
}
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.inspect -> string
|
|
|
|
*
|
|
|
|
* Creates a printable version of the digest object.
|
|
|
|
*/
|
2006-09-13 19:32:12 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_inspect(VALUE self)
|
2006-09-13 19:32:12 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
VALUE str;
|
|
|
|
size_t digest_len = 32; /* about this size at least */
|
2006-09-13 19:32:12 -04:00
|
|
|
char *cname;
|
|
|
|
|
|
|
|
cname = rb_obj_classname(self);
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/* #<Digest::ClassName: xxxxx...xxxx> */
|
2006-10-05 13:39:51 -04:00
|
|
|
str = rb_str_buf_new(2 + strlen(cname) + 2 + digest_len * 2 + 1);
|
2006-09-13 19:32:12 -04:00
|
|
|
rb_str_buf_cat2(str, "#<");
|
|
|
|
rb_str_buf_cat2(str, cname);
|
|
|
|
rb_str_buf_cat2(str, ": ");
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_str_buf_append(str, rb_digest_instance_hexdigest(0, 0, self));
|
2006-09-13 19:32:12 -04:00
|
|
|
rb_str_buf_cat2(str, ">");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2006-10-13 07:52:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj == another_digest_obj -> boolean
|
2006-10-20 08:48:35 -04:00
|
|
|
* digest_obj == string -> boolean
|
2006-10-13 07:52:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* If a string is given, checks whether it is equal to the hex-encoded
|
2006-11-01 00:01:43 -05:00
|
|
|
* hash value of the digest object. If another digest instance is
|
|
|
|
* given, checks whether they have the same hash value. Otherwise
|
|
|
|
* returns false.
|
2006-10-13 07:52:18 -04:00
|
|
|
*/
|
2001-07-13 16:06:14 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_equal(VALUE self, VALUE other)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
|
|
|
VALUE str1, str2;
|
|
|
|
|
2006-11-01 00:01:43 -05:00
|
|
|
if (rb_obj_is_kind_of(other, rb_mDigest_Instance) == Qtrue) {
|
2006-10-20 08:48:35 -04:00
|
|
|
str1 = rb_digest_instance_digest(0, 0, self);
|
|
|
|
str2 = rb_digest_instance_digest(0, 0, other);
|
2006-10-11 08:43:58 -04:00
|
|
|
} else {
|
2006-10-20 08:48:35 -04:00
|
|
|
str1 = rb_digest_instance_to_s(self);
|
2006-10-11 08:43:58 -04:00
|
|
|
str2 = other;
|
2001-07-13 16:06:14 -04:00
|
|
|
}
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/* never blindly assume that subclass methods return strings */
|
|
|
|
StringValue(str1);
|
|
|
|
StringValue(str2);
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
if (RSTRING_LEN(str1) == RSTRING_LEN(str2) &&
|
|
|
|
rb_str_cmp(str1, str2) == 0) {
|
|
|
|
return Qtrue;
|
|
|
|
}
|
2001-07-13 16:06:14 -04:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-20 08:48:35 -04:00
|
|
|
* digest_obj.digest_length -> integer
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* Returns the length of the hash value of the digest.
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* This method should be overridden by each implementation subclass.
|
|
|
|
* If not, digest_obj.digest().length() is returned.
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
*/
|
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_digest_length(VALUE self)
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
/* subclasses really should redefine this method */
|
|
|
|
VALUE digest = rb_digest_instance_digest(0, 0, self);
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/* never blindly assume that #digest() returns a string */
|
|
|
|
StringValue(digest);
|
|
|
|
return INT2NUM(RSTRING_LEN(digest));
|
|
|
|
}
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.length -> integer
|
|
|
|
* digest_obj.size -> integer
|
|
|
|
*
|
|
|
|
* Returns digest_obj.digest_length().
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_digest_instance_length(VALUE self)
|
|
|
|
{
|
|
|
|
return rb_funcall(self, id_digest_length, 0);
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.block_length -> integer
|
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* Returns the block length of the digest.
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* This method is overridden by each implementation subclass.
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
*/
|
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_instance_block_length(VALUE self)
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
{
|
2007-07-15 09:24:39 -04:00
|
|
|
rb_raise(rb_eRuntimeError, "%s does not implement block_length()", RSTRING_PTR(rb_inspect(self)));
|
2006-10-20 08:48:35 -04:00
|
|
|
}
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/*
|
|
|
|
* Document-class: Digest::Class
|
|
|
|
*
|
|
|
|
* This module stands as a base class for digest implementation
|
|
|
|
* classes.
|
|
|
|
*/
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Digest::Class.digest(string, *parameters) -> hash_string
|
|
|
|
*
|
|
|
|
* Returns the hash value of a given _string_. This is equivalent to
|
|
|
|
* Digest::Class.new(*parameters).digest(string), where extra
|
|
|
|
* _parameters_, if any, are passed through to the constructor and the
|
|
|
|
* _string_ is passed to #digest().
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_digest_class_s_digest(int argc, VALUE *argv, VALUE klass)
|
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
volatile VALUE obj;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
rb_raise(rb_eArgError, "no data given");
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
}
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
str = *argv++;
|
|
|
|
argc--;
|
|
|
|
|
|
|
|
StringValue(str);
|
|
|
|
|
|
|
|
obj = rb_obj_alloc(klass);
|
|
|
|
rb_obj_call_init(obj, argc, argv);
|
|
|
|
|
|
|
|
return rb_funcall(obj, id_digest, 1, str);
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-20 08:48:35 -04:00
|
|
|
* Digest::Class.hexdigest(string[, ...]) -> hash_string
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* Returns the hex-encoded hash value of a given _string_. This is
|
|
|
|
* almost equivalent to
|
|
|
|
* Digest.hexencode(Digest::Class.new(*parameters).digest(string)).
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_digest_class_s_hexdigest(int argc, VALUE *argv, VALUE klass)
|
|
|
|
{
|
|
|
|
return hexencode_str_new(rb_funcall2(klass, id_digest, argc, argv));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: Digest::Base
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
*
|
2006-10-20 08:48:35 -04:00
|
|
|
* This abstract class provides a common interface to message digest
|
|
|
|
* implementation classes written in C.
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
*/
|
2006-10-20 08:48:35 -04:00
|
|
|
|
|
|
|
static rb_digest_metadata_t *
|
|
|
|
get_digest_base_metadata(VALUE klass)
|
|
|
|
{
|
2007-02-28 13:24:25 -05:00
|
|
|
VALUE p;
|
2006-10-20 08:48:35 -04:00
|
|
|
VALUE obj;
|
|
|
|
rb_digest_metadata_t *algo;
|
|
|
|
|
2007-09-28 02:21:46 -04:00
|
|
|
for (p = klass; p; p = RCLASS_SUPER(p)) {
|
2007-02-28 13:24:25 -05:00
|
|
|
if (rb_ivar_defined(p, id_metadata)) {
|
|
|
|
obj = rb_ivar_get(p, id_metadata);
|
|
|
|
break;
|
|
|
|
}
|
2006-10-20 08:48:35 -04:00
|
|
|
}
|
|
|
|
|
2007-02-28 13:24:25 -05:00
|
|
|
if (!p)
|
2007-02-28 13:27:50 -05:00
|
|
|
rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");
|
2006-10-20 08:48:35 -04:00
|
|
|
|
|
|
|
Data_Get_Struct(obj, rb_digest_metadata_t, algo);
|
|
|
|
|
|
|
|
switch (algo->api_version) {
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* put conversion here if possible when API is updated
|
|
|
|
*/
|
|
|
|
|
|
|
|
default:
|
|
|
|
rb_raise(rb_eRuntimeError, "Incompatible digest API version");
|
|
|
|
}
|
|
|
|
|
|
|
|
return algo;
|
|
|
|
}
|
|
|
|
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_base_alloc(VALUE klass)
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_metadata_t *algo;
|
|
|
|
VALUE obj;
|
|
|
|
void *pctx;
|
|
|
|
|
|
|
|
if (klass == rb_cDigest_Base) {
|
|
|
|
rb_raise(rb_eNotImpError, "Digest::Base is an abstract class");
|
|
|
|
}
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
|
|
|
algo = get_digest_base_metadata(klass);
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
pctx = xmalloc(algo->ctx_size);
|
|
|
|
algo->init_func(pctx);
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
obj = Data_Wrap_Struct(klass, 0, free, pctx);
|
|
|
|
|
|
|
|
return obj;
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
}
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/* :nodoc: */
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
static VALUE
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_base_copy(VALUE copy, VALUE obj)
|
|
|
|
{
|
|
|
|
rb_digest_metadata_t *algo;
|
|
|
|
void *pctx1, *pctx2;
|
|
|
|
|
|
|
|
if (copy == obj) return copy;
|
|
|
|
|
|
|
|
rb_check_frozen(copy);
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(rb_obj_class(copy));
|
|
|
|
|
|
|
|
Data_Get_Struct(obj, void, pctx1);
|
|
|
|
Data_Get_Struct(copy, void, pctx2);
|
|
|
|
memcpy(pctx2, pctx1, algo->ctx_size);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* :nodoc: */
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_reset(VALUE self)
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_metadata_t *algo;
|
|
|
|
void *pctx;
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
Data_Get_Struct(self, void, pctx);
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
algo->init_func(pctx);
|
|
|
|
|
|
|
|
return self;
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
}
|
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/* :nodoc: */
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_update(VALUE self, VALUE str)
|
2001-07-13 16:06:14 -04:00
|
|
|
{
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_digest_metadata_t *algo;
|
|
|
|
void *pctx;
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
Data_Get_Struct(self, void, pctx);
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
StringValue(str);
|
2007-02-27 05:08:39 -05:00
|
|
|
algo->update_func(pctx, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
return self;
|
|
|
|
}
|
2001-07-13 16:06:14 -04:00
|
|
|
|
2006-10-20 08:48:35 -04:00
|
|
|
/* :nodoc: */
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_finish(VALUE self)
|
|
|
|
{
|
|
|
|
rb_digest_metadata_t *algo;
|
|
|
|
void *pctx;
|
|
|
|
VALUE str;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
|
|
|
|
|
|
|
Data_Get_Struct(self, void, pctx);
|
|
|
|
|
|
|
|
str = rb_str_new(0, algo->digest_len);
|
2007-02-27 05:08:39 -05:00
|
|
|
algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str));
|
2006-10-20 08:48:35 -04:00
|
|
|
|
|
|
|
/* avoid potential coredump caused by use of a finished context */
|
|
|
|
algo->init_func(pctx);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* :nodoc: */
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_digest_length(VALUE self)
|
|
|
|
{
|
|
|
|
rb_digest_metadata_t *algo;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
|
|
|
|
|
|
|
return INT2NUM(algo->digest_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* :nodoc: */
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_block_length(VALUE self)
|
|
|
|
{
|
|
|
|
rb_digest_metadata_t *algo;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
|
|
|
|
|
|
|
return INT2NUM(algo->block_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Init_digest(void)
|
|
|
|
{
|
|
|
|
id_reset = rb_intern("reset");
|
|
|
|
id_update = rb_intern("update");
|
|
|
|
id_finish = rb_intern("finish");
|
|
|
|
id_digest = rb_intern("digest");
|
|
|
|
id_hexdigest = rb_intern("hexdigest");
|
|
|
|
id_digest_length = rb_intern("digest_length");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* module Digest
|
|
|
|
*/
|
|
|
|
rb_mDigest = rb_define_module("Digest");
|
|
|
|
|
|
|
|
/* module functions */
|
|
|
|
rb_define_module_function(rb_mDigest, "hexencode", rb_digest_s_hexencode, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* module Digest::Instance
|
|
|
|
*/
|
|
|
|
rb_mDigest_Instance = rb_define_module_under(rb_mDigest, "Instance");
|
|
|
|
|
|
|
|
/* instance methods that should be overridden */
|
|
|
|
rb_define_method(rb_mDigest_Instance, "update", rb_digest_instance_update, 1);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "<<", rb_digest_instance_update, 1);
|
|
|
|
rb_define_private_method(rb_mDigest_Instance, "finish", rb_digest_instance_finish, 0);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "reset", rb_digest_instance_reset, 0);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "digest_length", rb_digest_instance_digest_length, 0);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "block_length", rb_digest_instance_block_length, 0);
|
|
|
|
|
|
|
|
/* instance methods that may be overridden */
|
|
|
|
rb_define_method(rb_mDigest_Instance, "==", rb_digest_instance_equal, 1);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "inspect", rb_digest_instance_inspect, 0);
|
|
|
|
|
|
|
|
/* instance methods that need not usually be overridden */
|
|
|
|
rb_define_method(rb_mDigest_Instance, "new", rb_digest_instance_new, 0);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "digest", rb_digest_instance_digest, -1);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "digest!", rb_digest_instance_digest_bang, 0);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "hexdigest", rb_digest_instance_hexdigest, -1);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "hexdigest!", rb_digest_instance_hexdigest_bang, 0);
|
2006-10-26 02:15:57 -04:00
|
|
|
rb_define_method(rb_mDigest_Instance, "to_s", rb_digest_instance_to_s, 0);
|
2006-10-20 08:48:35 -04:00
|
|
|
rb_define_method(rb_mDigest_Instance, "length", rb_digest_instance_length, 0);
|
|
|
|
rb_define_method(rb_mDigest_Instance, "size", rb_digest_instance_length, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* class Digest::Class
|
|
|
|
*/
|
|
|
|
rb_cDigest_Class = rb_define_class_under(rb_mDigest, "Class", rb_cObject);
|
|
|
|
rb_include_module(rb_cDigest_Class, rb_mDigest_Instance);
|
|
|
|
|
|
|
|
/* class methods */
|
|
|
|
rb_define_singleton_method(rb_cDigest_Class, "digest", rb_digest_class_s_digest, -1);
|
|
|
|
rb_define_singleton_method(rb_cDigest_Class, "hexdigest", rb_digest_class_s_hexdigest, -1);
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-13 19:23:18 -04:00
|
|
|
|
2001-07-13 16:06:14 -04:00
|
|
|
id_metadata = rb_intern("metadata");
|
2006-10-20 08:48:35 -04:00
|
|
|
|
|
|
|
/* class Digest::Base < Digest::Class */
|
|
|
|
rb_cDigest_Base = rb_define_class_under(rb_mDigest, "Base", rb_cDigest_Class);
|
|
|
|
|
|
|
|
rb_define_alloc_func(rb_cDigest_Base, rb_digest_base_alloc);
|
|
|
|
|
|
|
|
rb_define_method(rb_cDigest_Base, "initialize_copy", rb_digest_base_copy, 1);
|
|
|
|
rb_define_method(rb_cDigest_Base, "reset", rb_digest_base_reset, 0);
|
|
|
|
rb_define_method(rb_cDigest_Base, "update", rb_digest_base_update, 1);
|
|
|
|
rb_define_method(rb_cDigest_Base, "<<", rb_digest_base_update, 1);
|
|
|
|
rb_define_private_method(rb_cDigest_Base, "finish", rb_digest_base_finish, 0);
|
|
|
|
rb_define_method(rb_cDigest_Base, "digest_length", rb_digest_base_digest_length, 0);
|
|
|
|
rb_define_method(rb_cDigest_Base, "block_length", rb_digest_base_block_length, 0);
|
2001-07-13 16:06:14 -04:00
|
|
|
}
|