2001-07-13 20:06:14 +00:00
|
|
|
/************************************************
|
|
|
|
|
|
|
|
digest.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Fri May 25 08:57:27 JST 2001
|
|
|
|
|
|
|
|
Copyright (C) 1995-2001 Yukihiro Matsumoto
|
2006-10-05 19:13:00 +00:00
|
|
|
Copyright (C) 2001-2006 Akinori MUSHA
|
2001-07-13 20:06:14 +00:00
|
|
|
|
|
|
|
$RoughId: digest.c,v 1.16 2001/07/13 15:38:27 knu Exp $
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
|
|
#include "digest.h"
|
|
|
|
|
|
|
|
static VALUE mDigest, cDigest_Base;
|
2006-10-11 06:05:32 +00:00
|
|
|
static ID id_metadata, id_new, id_initialize, id_update, id_digest;
|
2001-07-13 20:06:14 +00:00
|
|
|
|
|
|
|
/*
|
2006-10-13 11:52:18 +00:00
|
|
|
* Document-class: Digest
|
|
|
|
*
|
|
|
|
* This module provides a framework for message digest libraries.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: Digest::Base
|
|
|
|
*
|
|
|
|
* This class provides a common interface to message digest
|
|
|
|
* algorithms.
|
2001-07-13 20:06:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static algo_t *
|
2005-12-12 00:36:54 +00:00
|
|
|
get_digest_base_metadata(VALUE klass)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
|
|
|
VALUE obj;
|
|
|
|
algo_t *algo;
|
|
|
|
|
2006-10-11 17:14:54 +00:00
|
|
|
if (rb_ivar_defined(klass, id_metadata) == Qfalse) {
|
2006-10-05 17:39:51 +00:00
|
|
|
return NULL;
|
2002-09-03 05:20:14 +00:00
|
|
|
}
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2006-10-11 17:14:54 +00:00
|
|
|
obj = rb_ivar_get(klass, id_metadata);
|
2001-07-13 20:06:14 +00:00
|
|
|
|
|
|
|
Data_Get_Struct(obj, algo_t, 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 23:23:18 +00:00
|
|
|
if (algo->api_version != 1) {
|
|
|
|
/*
|
|
|
|
* put conversion here if possible when API is updated
|
|
|
|
*/
|
|
|
|
rb_raise(rb_eRuntimeError, "Incompatible digest API version");
|
|
|
|
}
|
|
|
|
|
2001-07-13 20:06:14 +00:00
|
|
|
return algo;
|
|
|
|
}
|
* array.c (ary_alloc), dir.c (dir_s_alloc), eval.c (thgroup_s_alloc),
file.c (rb_stat_s_alloc), hash.c (hash_alloc), io.c (io_alloc),
object.c (rb_module_s_alloc, rb_class_allocate_instance),
re.c (match_alloc, rb_reg_s_alloc), string.c (str_alloc),
time.c (time_s_alloc), ext/digest/digest.c (rb_digest_base_alloc),
ext/tcltklib/tcltklib.c (ip_alloc),
ext/win32ole/win32ole.c (fole_s_allocate, fev_s_allocate)
: add prototype to get rid of VC++ warnings.
* ext/sdbm/init.c (fsdbm_alloc): allocator takes only one argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-21 18:02:01 +00: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 11:09:42 +00:00
|
|
|
static VALUE
|
2006-10-05 19:13:00 +00:00
|
|
|
hexdigest_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 11:09:42 +00:00
|
|
|
{
|
2006-10-10 07:49:00 +00: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 11:09:42 +00:00
|
|
|
int i;
|
|
|
|
VALUE str;
|
|
|
|
char *p;
|
2006-10-05 17:07:59 +00:00
|
|
|
static const char hex[] = {
|
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
|
|
'a', 'b', 'c', 'd', 'e', 'f'
|
|
|
|
};
|
|
|
|
|
2006-10-10 07:49:00 +00:00
|
|
|
StringValue(str_digest);
|
|
|
|
digest = RSTRING_PTR(str_digest);
|
|
|
|
digest_len = RSTRING_LEN(str_digest);
|
|
|
|
|
2006-10-05 17:07:59 +00: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 11:09:42 +00: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;
|
|
|
|
}
|
|
|
|
|
2001-07-13 20:06:14 +00:00
|
|
|
static VALUE
|
2005-12-12 00:36:54 +00:00
|
|
|
rb_digest_base_alloc(VALUE klass)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
VALUE obj;
|
|
|
|
void *pctx;
|
|
|
|
|
2002-09-03 05:20:14 +00:00
|
|
|
if (klass == cDigest_Base) {
|
2001-07-13 20:06:14 +00:00
|
|
|
rb_raise(rb_eNotImpError, "Digest::Base is an abstract class");
|
2002-09-03 05:20:14 +00:00
|
|
|
}
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2002-09-03 05:20:14 +00:00
|
|
|
algo = get_digest_base_metadata(klass);
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2006-10-05 17:39:51 +00:00
|
|
|
if (algo == NULL) {
|
|
|
|
return Data_Wrap_Struct(klass, 0, free, 0);
|
|
|
|
}
|
|
|
|
|
2006-10-11 12:43:58 +00:00
|
|
|
pctx = xmalloc(algo->ctx_size);
|
2001-07-13 20:06:14 +00:00
|
|
|
algo->init_func(pctx);
|
|
|
|
|
2002-09-03 05:20:14 +00:00
|
|
|
obj = Data_Wrap_Struct(klass, 0, free, pctx);
|
2001-07-13 20:06:14 +00:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-13 19:40:01 +00:00
|
|
|
* Digest::ALGORITHM.digest(string[, ...]) -> hash_string
|
2006-10-13 11:52:18 +00:00
|
|
|
*
|
2006-10-13 19:40:01 +00:00
|
|
|
* Returns the hash value of a given string _data_. This is almost
|
|
|
|
* equivalent to Digest::ALGORITHM.new(...).update(string).digest()
|
2006-10-13 20:55:33 +00:00
|
|
|
* where extra arguments, if any, are passed through to the
|
|
|
|
* constructor.
|
2006-10-13 11:52:18 +00:00
|
|
|
*/
|
2001-07-13 20:06:14 +00:00
|
|
|
static VALUE
|
2006-10-13 19:40:01 +00:00
|
|
|
rb_digest_base_s_digest(int argc, VALUE *argv, VALUE klass)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
2006-10-13 19:40:01 +00:00
|
|
|
VALUE str;
|
|
|
|
algo_t *algo;
|
2001-07-13 20:06:14 +00:00
|
|
|
void *pctx;
|
2006-10-05 17:39:51 +00:00
|
|
|
volatile VALUE obj;
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2006-10-13 19:40:01 +00:00
|
|
|
if (argc < 1) {
|
|
|
|
rb_raise(rb_eArgError, "no data given");
|
|
|
|
}
|
|
|
|
|
|
|
|
str = *argv++;
|
|
|
|
argc--;
|
|
|
|
|
|
|
|
StringValue(str);
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(klass);
|
|
|
|
|
2006-10-05 17:39:51 +00:00
|
|
|
if (algo == NULL) {
|
2006-10-13 19:40:01 +00:00
|
|
|
VALUE obj = rb_funcall2(klass, id_new, argc, argv);
|
2006-10-05 17:39:51 +00:00
|
|
|
rb_funcall(obj, id_update, 1, str);
|
|
|
|
return rb_funcall(obj, id_digest, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = rb_digest_base_alloc(klass);
|
2002-09-03 05:20:14 +00:00
|
|
|
Data_Get_Struct(obj, void, pctx);
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2006-08-31 10:30:33 +00:00
|
|
|
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2005-12-12 00:36:54 +00:00
|
|
|
str = rb_str_new(0, algo->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 11:09:42 +00:00
|
|
|
algo->finish_func(pctx, RSTRING_PTR(str));
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2005-12-12 00:36:54 +00:00
|
|
|
return str;
|
2001-07-13 20:06:14 +00:00
|
|
|
}
|
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-13 19:40:01 +00:00
|
|
|
* Digest::ALGORITHM.hexdigest(string[, ...]) -> hash_string
|
2006-10-13 11:52:18 +00:00
|
|
|
*
|
2006-10-13 19:40:01 +00:00
|
|
|
* Returns the hex-encoded hash value of a given _string_. This
|
|
|
|
* method just hex-encode the return value of
|
|
|
|
* Digest::ALGORITHM.digest(string[, ...]) where extra arguments, if
|
2006-10-13 20:55:33 +00:00
|
|
|
* any, are passed through along with the _string_.
|
2006-10-13 11:52:18 +00:00
|
|
|
*/
|
2001-07-13 20:06:14 +00:00
|
|
|
static VALUE
|
2006-10-13 19:40:01 +00:00
|
|
|
rb_digest_base_s_hexdigest(int argc, VALUE *argv, VALUE klass)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
2006-10-13 19:40:01 +00:00
|
|
|
return hexdigest_str_new(rb_funcall2(klass, id_digest, argc, argv));
|
2006-10-05 19:13:00 +00:00
|
|
|
}
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2006-10-13 19:40:01 +00:00
|
|
|
/* :nodoc: */
|
2001-07-13 20:06:14 +00:00
|
|
|
static VALUE
|
2005-12-12 00:36:54 +00:00
|
|
|
rb_digest_base_copy(VALUE copy, VALUE obj)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
void *pctx1, *pctx2;
|
2002-09-03 05:20:14 +00:00
|
|
|
|
2002-09-05 02:11:41 +00:00
|
|
|
if (copy == obj) return copy;
|
2002-09-03 05:20:14 +00:00
|
|
|
rb_check_frozen(copy);
|
2004-09-17 09:24:13 +00:00
|
|
|
algo = get_digest_base_metadata(rb_obj_class(copy));
|
2006-10-05 17:39:51 +00:00
|
|
|
|
2006-10-11 06:05:32 +00:00
|
|
|
if (algo == NULL) {
|
2006-10-11 12:43:58 +00:00
|
|
|
/* initialize_copy() is undefined or something */
|
2006-10-05 17:39:51 +00:00
|
|
|
rb_notimplement();
|
2006-10-11 06:05:32 +00:00
|
|
|
}
|
2006-10-05 17:39:51 +00:00
|
|
|
|
|
|
|
/* get_digest_base_metadata() may return a NULL */
|
2004-09-17 09:24:13 +00:00
|
|
|
if (algo != get_digest_base_metadata(rb_obj_class(obj))) {
|
2002-09-03 05:20:14 +00:00
|
|
|
rb_raise(rb_eTypeError, "wrong argument class");
|
|
|
|
}
|
2002-09-04 09:21:07 +00:00
|
|
|
Data_Get_Struct(obj, void, pctx1);
|
2002-09-03 05:20:14 +00:00
|
|
|
Data_Get_Struct(copy, void, pctx2);
|
2001-07-13 20:06:14 +00:00
|
|
|
memcpy(pctx2, pctx1, algo->ctx_size);
|
|
|
|
|
2002-09-03 05:20:14 +00:00
|
|
|
return copy;
|
2001-07-13 20:06:14 +00:00
|
|
|
}
|
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.reset -> digest_obj
|
|
|
|
*
|
|
|
|
* Resets the digest to the initial state and returns self.
|
2006-10-13 20:55:33 +00:00
|
|
|
*
|
|
|
|
* Every implementation subclass which constructor takes arguments
|
|
|
|
* must redefine this method because Digest::Base#reset() internally
|
|
|
|
* calls initialize() with no argument.
|
2006-10-13 11:52:18 +00:00
|
|
|
*/
|
2006-10-11 05:15:15 +00:00
|
|
|
static VALUE
|
|
|
|
rb_digest_base_reset(VALUE self)
|
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
void *pctx;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
|
|
|
|
|
|
|
if (algo == NULL) {
|
2006-10-11 06:05:32 +00:00
|
|
|
rb_funcall(self, id_initialize, 0);
|
2006-10-11 05:15:15 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
Data_Get_Struct(self, void, pctx);
|
|
|
|
|
|
|
|
memset(pctx, 0, algo->ctx_size);
|
|
|
|
algo->init_func(pctx);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-13 19:40:01 +00:00
|
|
|
* digest_obj.update(string) -> digest_obj
|
2006-10-13 11:52:18 +00:00
|
|
|
*
|
2006-10-13 19:40:01 +00:00
|
|
|
* Updates the digest using a given _string_ and returns self.
|
2006-10-13 20:55:33 +00: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 23:23:18 +00:00
|
|
|
* Implementation subclasses must redefine this method, and should
|
|
|
|
* make `<<' an alias to it.
|
2006-10-13 11:52:18 +00:00
|
|
|
*/
|
2001-07-13 20:06:14 +00:00
|
|
|
static VALUE
|
2005-12-12 00:36:54 +00:00
|
|
|
rb_digest_base_update(VALUE self, VALUE str)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
void *pctx;
|
|
|
|
|
2006-10-05 17:39:51 +00:00
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
|
|
|
|
|
|
|
if (algo == NULL) {
|
|
|
|
/* subclasses must define update() */
|
|
|
|
rb_notimplement();
|
|
|
|
}
|
|
|
|
|
|
|
|
Data_Get_Struct(self, void, pctx);
|
|
|
|
|
2001-07-13 20:06:14 +00:00
|
|
|
StringValue(str);
|
2006-10-05 17:39:51 +00:00
|
|
|
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-10-13 19:40:01 +00:00
|
|
|
* digest_obj << string -> digest_obj
|
2006-10-13 11:52:18 +00:00
|
|
|
*
|
2006-10-13 19:40:01 +00:00
|
|
|
* Calls update(string).
|
2006-10-13 20:55:33 +00: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 23:23:18 +00:00
|
|
|
* Implementation subclasses need not but should alias this method to
|
|
|
|
* update() to eliminate chain calls.
|
2006-10-13 11:52:18 +00:00
|
|
|
*/
|
2006-10-05 17:39:51 +00:00
|
|
|
static VALUE
|
|
|
|
rb_digest_base_lshift(VALUE self, VALUE str)
|
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
void *pctx;
|
|
|
|
|
2004-09-17 09:24:13 +00:00
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
2006-10-05 17:39:51 +00:00
|
|
|
|
|
|
|
if (algo == NULL) {
|
|
|
|
/* subclasses just need to define update(), not << */
|
|
|
|
rb_funcall(self, id_update, 1, str);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2001-07-13 20:06:14 +00:00
|
|
|
Data_Get_Struct(self, void, pctx);
|
|
|
|
|
2006-10-05 17:39:51 +00:00
|
|
|
StringValue(str);
|
2006-08-31 10:30:33 +00:00
|
|
|
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
|
2001-07-13 20:06:14 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.digest -> string
|
|
|
|
*
|
|
|
|
* Returns the resulting hash value.
|
2006-10-13 20:55:33 +00:00
|
|
|
*
|
|
|
|
* Implementation subclasses must redefine this method.
|
2006-10-13 11:52:18 +00:00
|
|
|
*/
|
2001-07-13 20:06:14 +00:00
|
|
|
static VALUE
|
2005-12-12 00:36:54 +00:00
|
|
|
rb_digest_base_digest(VALUE self)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
void *pctx1, *pctx2;
|
* 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 11:09:42 +00:00
|
|
|
size_t ctx_size;
|
2001-07-13 20:06:14 +00:00
|
|
|
VALUE str;
|
|
|
|
|
2004-09-17 09:24:13 +00:00
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
2006-10-05 17:39:51 +00:00
|
|
|
|
2006-10-11 06:05:32 +00:00
|
|
|
if (algo == NULL) {
|
|
|
|
/* subclasses must define update() */
|
2006-10-05 17:39:51 +00:00
|
|
|
rb_notimplement();
|
2006-10-11 06:05:32 +00:00
|
|
|
}
|
2006-10-05 17:39:51 +00:00
|
|
|
|
2001-07-13 20:06:14 +00:00
|
|
|
Data_Get_Struct(self, void, pctx1);
|
|
|
|
|
* 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 11:09:42 +00:00
|
|
|
ctx_size = algo->ctx_size;
|
|
|
|
pctx2 = xmalloc(ctx_size);
|
|
|
|
memcpy(pctx2, pctx1, ctx_size);
|
2001-07-13 20:06:14 +00: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 11:09:42 +00:00
|
|
|
str = rb_str_new(0, algo->digest_len);
|
|
|
|
algo->finish_func(pctx2, RSTRING_PTR(str));
|
2001-07-13 20:06:14 +00:00
|
|
|
free(pctx2);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.hexdigest -> string
|
|
|
|
* digest_obj.to_s -> string
|
|
|
|
*
|
|
|
|
* Returns the resulting hash value in a hex-encoded form.
|
|
|
|
*/
|
2001-07-13 20:06:14 +00:00
|
|
|
static VALUE
|
2005-12-12 00:36:54 +00:00
|
|
|
rb_digest_base_hexdigest(VALUE self)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
2006-10-05 19:13:00 +00:00
|
|
|
return hexdigest_str_new(rb_funcall(self, id_digest, 0));
|
|
|
|
}
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.inspect -> string
|
|
|
|
*
|
|
|
|
* Creates a printable version of the digest object.
|
|
|
|
*/
|
2006-09-13 23:32:12 +00:00
|
|
|
static VALUE
|
|
|
|
rb_digest_base_inspect(VALUE self)
|
|
|
|
{
|
|
|
|
algo_t *algo;
|
2006-10-05 17:39:51 +00:00
|
|
|
VALUE klass, str;
|
|
|
|
size_t digest_len = 32; /* no need to be just the right size */
|
2006-09-13 23:32:12 +00:00
|
|
|
char *cname;
|
|
|
|
|
2006-10-05 17:39:51 +00:00
|
|
|
klass = rb_obj_class(self);
|
|
|
|
algo = get_digest_base_metadata(klass);
|
|
|
|
|
|
|
|
if (algo != NULL)
|
|
|
|
digest_len = algo->digest_len;
|
2006-09-13 23:32:12 +00:00
|
|
|
|
|
|
|
cname = rb_obj_classname(self);
|
|
|
|
|
|
|
|
/* #<Digest::Alg: xxxxx...xxxx> */
|
2006-10-05 17:39:51 +00:00
|
|
|
str = rb_str_buf_new(2 + strlen(cname) + 2 + digest_len * 2 + 1);
|
2006-09-13 23:32:12 +00:00
|
|
|
rb_str_buf_cat2(str, "#<");
|
|
|
|
rb_str_buf_cat2(str, cname);
|
|
|
|
rb_str_buf_cat2(str, ": ");
|
|
|
|
rb_str_buf_append(str, rb_digest_base_hexdigest(self));
|
|
|
|
rb_str_buf_cat2(str, ">");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2006-10-13 11:52:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj == string -> boolean
|
|
|
|
* digest_obj == another_digest_obj -> boolean
|
|
|
|
*
|
|
|
|
* If a string is given, checks whether it is equal to the hash value
|
|
|
|
* of the digest object. If another instance of the same digest class
|
|
|
|
* is given, checks whether they have the same hash value. Otherwise
|
|
|
|
* returns false.
|
|
|
|
*/
|
2001-07-13 20:06:14 +00:00
|
|
|
static VALUE
|
2005-12-12 00:36:54 +00:00
|
|
|
rb_digest_base_equal(VALUE self, VALUE other)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
|
|
|
algo_t *algo;
|
2002-09-03 05:20:14 +00:00
|
|
|
VALUE klass;
|
2001-07-13 20:06:14 +00:00
|
|
|
VALUE str1, str2;
|
|
|
|
|
2004-09-17 09:24:13 +00:00
|
|
|
klass = rb_obj_class(self);
|
2001-07-13 20:06:14 +00:00
|
|
|
|
2004-09-17 09:24:13 +00:00
|
|
|
if (rb_obj_class(other) == klass) {
|
2006-10-12 17:43:17 +00:00
|
|
|
str1 = rb_funcall(self, id_digest, 0);
|
|
|
|
str2 = rb_funcall(other, id_digest, 0);
|
2006-10-11 12:43:58 +00:00
|
|
|
} else {
|
|
|
|
StringValue(other);
|
|
|
|
str2 = other;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(klass);
|
|
|
|
|
|
|
|
if (RSTRING_LEN(str2) == algo->digest_len)
|
2006-10-13 10:55:51 +00:00
|
|
|
str1 = rb_funcall(self, id_digest, 0);
|
2006-10-11 12:43:58 +00:00
|
|
|
else
|
|
|
|
str1 = rb_digest_base_hexdigest(self);
|
2001-07-13 20:06:14 +00:00
|
|
|
}
|
|
|
|
|
2006-08-31 10:30:33 +00:00
|
|
|
if (RSTRING_LEN(str1) == RSTRING_LEN(str2)
|
2005-12-12 00:36:54 +00:00
|
|
|
&& rb_str_cmp(str1, str2) == 0)
|
2001-07-13 20:06:14 +00:00
|
|
|
return Qtrue;
|
|
|
|
|
|
|
|
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 23:23:18 +00:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Digest::ALGORITHM.block_length(...) -> integer
|
|
|
|
*
|
|
|
|
* Returns the digest length of the digest algorithm. Parameters
|
|
|
|
* follow the same specification as the constructor.
|
|
|
|
*
|
|
|
|
* If an implementation subclass does not redefine this method,
|
|
|
|
* returns Digest::ALGORITHM.new(...).digest_length().
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_s_digest_length(int argc, VALUE *argv,VALUE klass)
|
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(klass);
|
|
|
|
|
|
|
|
if (algo == NULL) {
|
|
|
|
/* Subclasses really should redefine this method */
|
|
|
|
VALUE obj = rb_funcall2(klass, id_new, argc, argv);
|
|
|
|
return rb_funcall(obj, rb_intern("digest_length"), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return INT2NUM(algo->digest_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.block_length -> integer
|
|
|
|
*
|
|
|
|
* Returns the length of the hash value of the digest object.
|
|
|
|
*
|
|
|
|
* If an implementation subclass does not redefine this method,
|
|
|
|
* returns digest_obj.digest().length().
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_digest_length(VALUE self)
|
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
|
|
|
|
|
|
|
if (algo == NULL) {
|
|
|
|
/* subclasses really should redefine this method */
|
|
|
|
VALUE digest = rb_funcall(self, id_digest, 0);
|
|
|
|
StringValue(digest);
|
|
|
|
return INT2NUM(RSTRING_LEN(digest));
|
|
|
|
}
|
|
|
|
|
|
|
|
return INT2NUM(algo->digest_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Digest::ALGORITHM.block_length(...) -> integer
|
|
|
|
*
|
|
|
|
* Returns the block length of the digest algorithm. Parameters
|
|
|
|
* follow the same specification as the constructor.
|
|
|
|
*
|
|
|
|
* If an implementation subclass does not redefine this method,
|
|
|
|
* returns Digest::ALGORITHM.new(...).block_length().
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_s_block_length(int argc, VALUE *argv,VALUE klass)
|
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(klass);
|
|
|
|
|
|
|
|
if (algo == NULL) {
|
|
|
|
VALUE obj = rb_funcall2(klass, id_new, argc, argv);
|
|
|
|
return rb_funcall(obj, rb_intern("block_length"), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return INT2NUM(algo->block_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* digest_obj.block_length -> length
|
|
|
|
*
|
|
|
|
* Returns the block length of the digest.
|
|
|
|
*
|
|
|
|
* Implementation subclasses must redefine this method if used.
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_digest_base_block_length(VALUE self)
|
|
|
|
{
|
|
|
|
algo_t *algo;
|
|
|
|
|
|
|
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
|
|
|
|
|
|
|
if (algo == NULL) {
|
|
|
|
/* subclasses must define this method (only if used) */
|
|
|
|
rb_notimplement();
|
|
|
|
}
|
|
|
|
|
|
|
|
return INT2NUM(algo->block_len);
|
|
|
|
}
|
|
|
|
|
2001-07-13 20:06:14 +00:00
|
|
|
void
|
2006-08-28 02:31:58 +00:00
|
|
|
Init_digest(void)
|
2001-07-13 20:06:14 +00:00
|
|
|
{
|
|
|
|
mDigest = rb_define_module("Digest");
|
|
|
|
|
|
|
|
cDigest_Base = rb_define_class_under(mDigest, "Base", rb_cObject);
|
|
|
|
|
* ext/curses/curses.c, ext/digest/digest.c, ext/dl/handle.c,
ext/dl/ptr.c, ext/dl/sym.c, ext/gdbm/gdbm.c, ext/iconv/iconv.c,
ext/stringio/stringio.c, ext/strscan/strscan.c,
ext/tcltklib/tcltklib.c, ext/win32ole/win32ole.c:
use rb_define_alloc_func().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-20 11:23:40 +00:00
|
|
|
rb_define_alloc_func(cDigest_Base, rb_digest_base_alloc);
|
2006-10-13 19:40:01 +00:00
|
|
|
rb_define_singleton_method(cDigest_Base, "digest", rb_digest_base_s_digest, -1);
|
|
|
|
rb_define_singleton_method(cDigest_Base, "hexdigest", rb_digest_base_s_hexdigest, -1);
|
2001-07-13 20:06:14 +00: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 23:23:18 +00:00
|
|
|
rb_define_singleton_method(cDigest_Base, "digest_length", rb_digest_base_s_digest_length, -1);
|
|
|
|
rb_define_singleton_method(cDigest_Base, "block_length", rb_digest_base_s_block_length, -1);
|
|
|
|
|
2003-09-29 02:44:49 +00:00
|
|
|
rb_define_method(cDigest_Base, "initialize_copy", rb_digest_base_copy, 1);
|
2006-10-11 05:15:15 +00:00
|
|
|
rb_define_method(cDigest_Base, "reset", rb_digest_base_reset, 0);
|
2001-07-13 20:06:14 +00:00
|
|
|
rb_define_method(cDigest_Base, "update", rb_digest_base_update, 1);
|
2006-10-05 17:39:51 +00:00
|
|
|
rb_define_method(cDigest_Base, "<<", rb_digest_base_lshift, 1);
|
2001-07-13 20:06:14 +00:00
|
|
|
rb_define_method(cDigest_Base, "digest", rb_digest_base_digest, 0);
|
|
|
|
rb_define_method(cDigest_Base, "hexdigest", rb_digest_base_hexdigest, 0);
|
|
|
|
rb_define_method(cDigest_Base, "to_s", rb_digest_base_hexdigest, 0);
|
2006-09-13 23:32:12 +00:00
|
|
|
rb_define_method(cDigest_Base, "inspect", rb_digest_base_inspect, 0);
|
2001-07-13 20:06:14 +00:00
|
|
|
rb_define_method(cDigest_Base, "==", rb_digest_base_equal, 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 23:23:18 +00:00
|
|
|
rb_define_method(cDigest_Base, "digest_length", rb_digest_base_digest_length, 0);
|
|
|
|
rb_define_method(cDigest_Base, "block_length", rb_digest_base_block_length, 0);
|
|
|
|
|
2001-07-13 20:06:14 +00:00
|
|
|
id_metadata = rb_intern("metadata");
|
2006-10-05 17:39:51 +00:00
|
|
|
id_new = rb_intern("new");
|
2006-10-11 06:05:32 +00:00
|
|
|
id_initialize = rb_intern("initialize");
|
2006-10-05 17:39:51 +00:00
|
|
|
id_update = rb_intern("update");
|
|
|
|
id_digest = rb_intern("digest");
|
2001-07-13 20:06:14 +00:00
|
|
|
}
|