From b337fc7fd16db204abedf5074f39cfd9b0ef1630 Mon Sep 17 00:00:00 2001 From: knu Date: Fri, 13 Jul 2001 20:06:14 +0000 Subject: 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: http://svn.ruby-lang.org/repos/ruby/trunk@1609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/sha1/sha1-ruby.c | 111 --------------------------------------------------- 1 file changed, 111 deletions(-) delete mode 100644 ext/sha1/sha1-ruby.c (limited to 'ext/sha1/sha1-ruby.c') diff --git a/ext/sha1/sha1-ruby.c b/ext/sha1/sha1-ruby.c deleted file mode 100644 index abd704c63..000000000 --- a/ext/sha1/sha1-ruby.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "ruby.h" -#include "sha1.h" - -static VALUE cSHA1; - -static VALUE -sha1_update(obj, str) - VALUE obj; - struct RString *str; -{ - SHA1_CTX *sha1; - - Check_Type(str, T_STRING); - Data_Get_Struct(obj, SHA1_CTX, sha1); - SHA1Update(sha1, str->ptr, str->len); - - return obj; -} - -static VALUE -sha1_digest(obj) - VALUE obj; -{ - SHA1_CTX *sha1, ctx; - unsigned char digest[20]; - - Data_Get_Struct(obj, SHA1_CTX, sha1); - ctx = *sha1; - SHA1Final(digest, &ctx); - - return rb_str_new(digest, 20); -} - -static VALUE -sha1_hexdigest(obj) - VALUE obj; -{ - SHA1_CTX *sha1, ctx; - unsigned char digest[20]; - char buf[41]; - int i; - - Data_Get_Struct(obj, SHA1_CTX, sha1); - ctx = *sha1; - SHA1Final(digest, &ctx); - - for (i=0; i<20; i++) { - sprintf(buf+i*2, "%02x", digest[i]); - } - return rb_str_new(buf, 40); -} - -static VALUE -sha1_clone(obj) - VALUE obj; -{ - SHA1_CTX *sha1, *sha1_new; - - Data_Get_Struct(obj, SHA1_CTX, sha1); - obj = Data_Make_Struct(CLASS_OF(obj), SHA1_CTX, 0, free, sha1_new); - *sha1_new = *sha1; - - return obj; -} - -static VALUE -sha1_init(argc, argv, self) - int argc; - VALUE* argv; - VALUE self; -{ - VALUE arg; - - rb_scan_args(argc, argv, "01", &arg); - - if (!NIL_P(arg)) sha1_update(self, arg); - - return self; -} - -static VALUE -sha1_new(argc, argv, class) - int argc; - VALUE* argv; - VALUE class; -{ - VALUE obj; - SHA1_CTX *sha1; - - obj = Data_Make_Struct(class, SHA1_CTX, 0, free, sha1); - SHA1Init(sha1); - rb_obj_call_init(obj, argc, argv); - - return obj; -} - -void -Init_sha1() -{ - cSHA1 = rb_define_class("SHA1", rb_cObject); - - rb_define_singleton_method(cSHA1, "new", sha1_new, -1); - rb_define_singleton_method(cSHA1, "sha1", sha1_new, -1); - - rb_define_method(cSHA1, "update", sha1_update, 1); - rb_define_method(cSHA1, "initialize", sha1_init, -1); - rb_define_method(cSHA1, "<<", sha1_update, 1); - rb_define_method(cSHA1, "digest", sha1_digest, 0); - rb_define_method(cSHA1, "hexdigest", sha1_hexdigest, 0); - rb_define_method(cSHA1, "clone", sha1_clone, 0); -} -- cgit