summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-11 05:15:15 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-11 05:15:15 +0000
commitcd58f3313e1dd60895e1888290f7e433bec67208 (patch)
tree9f83d84fbcd020e86e23c6bf68aed78590fe490e /ext
parent55b9887f970c21fcf483e14f940e860498a9606c (diff)
* ext/digest/digest.c (rb_digest_base_reset, Init_digest): Add
Digest::Base#reset. * ext/digest/digest.h: Update the header comment. * ext/digest/md5/md5ossl.h, ext/digest/md5/md5init.c (Init_md5): Define DIGEST_LENGTH and BLOCK_LENGTH. * ext/digest/rmd160/rmd160init.c (Init_rmd160): Ditto. * ext/digest/sha1/sha1init.c (Init_sha1): Ditto. * ext/digest/sha2/sha2init.c (Init_sha2): Ditto. * ext/digest/depend, ext/digest/extconf.rb: Use $INSTALLFILES rather than adding make targets. [Pointed out by: nobu] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/digest/depend6
-rw-r--r--ext/digest/digest.c26
-rw-r--r--ext/digest/digest.h4
-rw-r--r--ext/digest/extconf.rb4
-rw-r--r--ext/digest/md5/md5init.c3
-rw-r--r--ext/digest/md5/md5ossl.h2
-rw-r--r--ext/digest/rmd160/rmd160init.c3
-rw-r--r--ext/digest/sha1/sha1init.c3
-rw-r--r--ext/digest/sha2/sha2init.c3
9 files changed, 45 insertions, 9 deletions
diff --git a/ext/digest/depend b/ext/digest/depend
index 1fd76db..43601a2 100644
--- a/ext/digest/depend
+++ b/ext/digest/depend
@@ -1,8 +1,2 @@
digest.o: digest.c digest.h $(hdrdir)/ruby.h $(topdir)/config.h \
$(hdrdir)/defines.h $(hdrdir)/intern.h
-
-install-so: install-h
-site-install-so: install-h
-
-install-h:
- $(INSTALL_DATA) $(srcdir)/digest.h $(RUBYARCHDIR)
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index 53c05f9..0e3bf47 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -16,7 +16,7 @@
#include "digest.h"
static VALUE mDigest, cDigest_Base;
-static ID id_metadata, id_new, id_update, id_digest;
+static ID id_metadata, id_new, id_reset, id_update, id_digest;
/*
* Digest::Base
@@ -222,6 +222,28 @@ rb_digest_base_copy(VALUE copy, VALUE obj)
}
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) {
+ rb_funcall(self, id_reset, 0);
+
+ return self;
+ }
+
+ Data_Get_Struct(self, void, pctx);
+
+ memset(pctx, 0, algo->ctx_size);
+ algo->init_func(pctx);
+
+ return self;
+}
+
+static VALUE
rb_digest_base_update(VALUE self, VALUE str)
{
algo_t *algo;
@@ -407,6 +429,7 @@ Init_digest(void)
rb_define_method(cDigest_Base, "initialize", rb_digest_base_init, -1);
rb_define_method(cDigest_Base, "initialize_copy", rb_digest_base_copy, 1);
+ rb_define_method(cDigest_Base, "reset", rb_digest_base_reset, 0);
rb_define_method(cDigest_Base, "update", rb_digest_base_update, 1);
rb_define_method(cDigest_Base, "<<", rb_digest_base_lshift, 1);
rb_define_method(cDigest_Base, "digest", rb_digest_base_digest, 0);
@@ -418,6 +441,7 @@ Init_digest(void)
id_metadata = rb_intern("metadata");
id_new = rb_intern("new");
+ id_reset = rb_intern("reset");
id_update = rb_intern("update");
id_digest = rb_intern("digest");
}
diff --git a/ext/digest/digest.h b/ext/digest/digest.h
index d9e5c70..98aa87c 100644
--- a/ext/digest/digest.h
+++ b/ext/digest/digest.h
@@ -1,12 +1,12 @@
/************************************************
- digest.c -
+ digest.h - header file for ruby digest modules
$Author$
created at: Fri May 25 08:54:56 JST 2001
- Copyright (C) 2001 Akinori MUSHA
+ Copyright (C) 2001-2006 Akinori MUSHA
$RoughId: digest.h,v 1.3 2001/07/13 15:38:27 knu Exp $
$Id$
diff --git a/ext/digest/extconf.rb b/ext/digest/extconf.rb
index cd51262..cf9127e 100644
--- a/ext/digest/extconf.rb
+++ b/ext/digest/extconf.rb
@@ -3,4 +3,8 @@
require "mkmf"
+$INSTALLFILES = {
+ "digest.h" => "$(RUBYARCHDIR)"
+}
+
create_makefile("digest")
diff --git a/ext/digest/md5/md5init.c b/ext/digest/md5/md5init.c
index 5fddb21..4dc0c3b 100644
--- a/ext/digest/md5/md5init.c
+++ b/ext/digest/md5/md5init.c
@@ -29,6 +29,9 @@ Init_md5()
cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base);
+ rb_define_const(cDigest_MD5, "DIGEST_LENGTH", INT2NUM(MD5_DIGEST_LENGTH));
+ rb_define_const(cDigest_MD5, "BLOCK_LENGTH", INT2NUM(MD5_BLOCK_LENGTH));
+
rb_cvar_set(cDigest_MD5, rb_intern("metadata"),
Data_Wrap_Struct(rb_cObject, 0, 0, &md5), Qtrue);
}
diff --git a/ext/digest/md5/md5ossl.h b/ext/digest/md5/md5ossl.h
index bccbe05..ec629c5 100644
--- a/ext/digest/md5/md5ossl.h
+++ b/ext/digest/md5/md5ossl.h
@@ -6,6 +6,8 @@
#include <stddef.h>
#include <openssl/md5.h>
+#define MD5_BLOCK_LENGTH MD5_CBLOCK
+
void MD5_Finish(MD5_CTX *pctx, unsigned char *digest);
int MD5_Equal(MD5_CTX *pctx1, MD5_CTX *pctx2);
diff --git a/ext/digest/rmd160/rmd160init.c b/ext/digest/rmd160/rmd160init.c
index b56211f..08f3f1f 100644
--- a/ext/digest/rmd160/rmd160init.c
+++ b/ext/digest/rmd160/rmd160init.c
@@ -30,6 +30,9 @@ Init_rmd160()
cDigest_RMD160 = rb_define_class_under(mDigest, "RMD160", cDigest_Base);
+ rb_define_const(cDigest_RMD160, "DIGEST_LENGTH", INT2NUM(RMD160_DIGEST_LENGTH));
+ rb_define_const(cDigest_RMD160, "BLOCK_LENGTH", INT2NUM(RMD160_BLOCK_LENGTH));
+
id_metadata = rb_intern("metadata");
rb_cvar_set(cDigest_RMD160, id_metadata,
diff --git a/ext/digest/sha1/sha1init.c b/ext/digest/sha1/sha1init.c
index a704dcb..8a132e4 100644
--- a/ext/digest/sha1/sha1init.c
+++ b/ext/digest/sha1/sha1init.c
@@ -29,6 +29,9 @@ Init_sha1()
cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);
+ rb_define_const(cDigest_SHA1, "DIGEST_LENGTH", INT2NUM(SHA1_DIGEST_LENGTH));
+ rb_define_const(cDigest_SHA1, "BLOCK_LENGTH", INT2NUM(SHA1_BLOCK_LENGTH));
+
rb_cvar_set(cDigest_SHA1, rb_intern("metadata"),
Data_Wrap_Struct(rb_cObject, 0, 0, &sha1), Qtrue);
}
diff --git a/ext/digest/sha2/sha2init.c b/ext/digest/sha2/sha2init.c
index 9484f2a..4fb845c 100644
--- a/ext/digest/sha2/sha2init.c
+++ b/ext/digest/sha2/sha2init.c
@@ -39,6 +39,9 @@ Init_sha2()
#define DEFINE_ALGO_CLASS(bitlen) \
cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
\
+ rb_define_const(cDigest_SHA##bitlen, "DIGEST_LENGTH", INT2NUM(SHA##bitlen##_DIGEST_LENGTH)); \
+ rb_define_const(cDigest_SHA##bitlen, "BLOCK_LENGTH", INT2NUM(SHA##bitlen##_BLOCK_LENGTH)); \
+\
rb_cvar_set(cDigest_SHA##bitlen, id_metadata, \
Data_Wrap_Struct(rb_cObject, 0, 0, &sha##bitlen), Qtrue);