summaryrefslogtreecommitdiff
path: root/ext/digest/digest.c
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/digest/digest.c
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/digest/digest.c')
-rw-r--r--ext/digest/digest.c26
1 files changed, 25 insertions, 1 deletions
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");
}