summaryrefslogtreecommitdiff
path: root/ext/md5/md5init.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-13 20:06:14 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-13 20:06:14 +0000
commit76d7dae26ab8b56dbafcec710fc42a5fb7d79840 (patch)
tree513cc8df433c60ad0d6249388a38ade5a651188e /ext/md5/md5init.c
parent6ecd6fe37bf6395850d3825bab3fb88d5d345c82 (diff)
Import the "digest" module and the submodules, from the Rough Ruby
project. ext/digest: This module provides the module Digest and the abstract class Digest::Base. ext/digest/md5 (which obsoletes ext/md5): This module provides the class Digest::MD5 which implements the MD5 Message-Digest Algorithm. ext/digest/rmd160: This module provides the class Digest::RMD160 which implements the RIPEMD-160 cryptographic hash function. ext/digest/sha1 (which obsoletes ext/sha1): This module provides the class Digest::SHA1 which implements the SHA-1 Secure Hash Algorithm. ext/digest/sha2: This module provides the classes Digest::SHA256, Digest::SHA384 and Digest::SHA512 which implement the SHA-256, SHA-384 and SHA-512 Secure Hash Algorithms, respectively. lib/md5.rb, lib/sha1.rb: These files are provided for backward compatibility. All these classes have the common API, which previously ext/md5 and ext/sha1 modules provided. While the new API keeps 100% backward compatibility, it has been enriched with several utility methods. Read digest.txt for further details. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/md5/md5init.c')
-rw-r--r--ext/md5/md5init.c123
1 files changed, 0 insertions, 123 deletions
diff --git a/ext/md5/md5init.c b/ext/md5/md5init.c
deleted file mode 100644
index f491b65a27..0000000000
--- a/ext/md5/md5init.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/************************************************
-
- md5init.c -
-
- $Author$
- created at: Fri Aug 2 09:24:12 JST 1996
-
- Copyright (C) 1995-2001 Yukihiro Matsumoto
-
-************************************************/
-/* This module provides an interface to the RSA Data Security,
- Inc. MD5 Message-Digest Algorithm, described in RFC 1321. */
-
-#include "ruby.h"
-#include "md5.h"
-
-static VALUE cMD5;
-
-static VALUE
-md5i_update(obj, str)
- VALUE obj, str;
-{
- md5_state_t *md5;
-
- StringValue(str);
- Data_Get_Struct(obj, md5_state_t, md5);
- md5_append(md5, RSTRING(str)->ptr, RSTRING(str)->len);
-
- return obj;
-}
-
-static VALUE
-md5i_digest(obj)
- VALUE obj;
-{
- md5_state_t *md5, ctx;
- md5_byte_t digest[16];
-
- Data_Get_Struct(obj, md5_state_t, md5);
- ctx = *md5;
- md5_finish(&ctx, digest);
-
- return rb_str_new(digest, 16);
-}
-
-static VALUE
-md5i_hexdigest(obj)
- VALUE obj;
-{
- md5_state_t *md5, ctx;
- md5_byte_t digest[16];
- char buf[33];
- int i;
-
- Data_Get_Struct(obj, md5_state_t, md5);
- ctx = *md5;
- md5_finish(&ctx, digest);
-
- for (i=0; i<16; i++) {
- sprintf(buf+i*2, "%02x", digest[i]);
- }
- return rb_str_new(buf, 32);
-}
-
-static VALUE
-md5i_clone(obj)
- VALUE obj;
-{
- md5_state_t *md5, *md5_new;
-
- Data_Get_Struct(obj, md5_state_t, md5);
- obj = Data_Make_Struct(CLASS_OF(obj), md5_state_t, 0, free, md5_new);
- *md5_new = *md5;
-
- return obj;
-}
-
-static VALUE
-md5i_init(argc, argv, self)
- int argc;
- VALUE* argv;
- VALUE self;
-{
- VALUE str;
-
- rb_scan_args(argc, argv, "01", &str);
-
- if (!NIL_P(str)) md5i_update(self, str);
-
- return self;
-}
-
-static VALUE
-md5i_new(argc, argv, class)
- int argc;
- VALUE* argv;
- VALUE class;
-{
- VALUE obj;
- md5_state_t *md5;
-
- obj = Data_Make_Struct(class, md5_state_t, 0, free, md5);
- md5_init(md5);
- rb_obj_call_init(obj, argc, argv);
-
- return obj;
-}
-
-void
-Init_md5()
-{
- cMD5 = rb_define_class("MD5", rb_cObject);
-
- rb_define_singleton_method(cMD5, "new", md5i_new, -1);
- rb_define_singleton_method(cMD5, "md5", md5i_new, -1);
-
- rb_define_method(cMD5, "initialize", md5i_init, -1);
- rb_define_method(cMD5, "update", md5i_update, 1);
- rb_define_method(cMD5, "<<", md5i_update, 1);
- rb_define_method(cMD5, "digest", md5i_digest, 0);
- rb_define_method(cMD5, "hexdigest", md5i_hexdigest, 0);
- rb_define_method(cMD5, "clone", md5i_clone, 0);
-}