зеркало из https://github.com/github/ruby.git
* ext/sha1/sha1-ruby.c (md5i_new): separate initialize() from
new(). * ext/md5/md5init.c (sha1_new): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
dcd6223c64
Коммит
d6e985ad0b
|
@ -1,3 +1,10 @@
|
||||||
|
Fri May 25 00:57:25 2001 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* ext/sha1/sha1-ruby.c (md5i_new): separate initialize() from
|
||||||
|
new().
|
||||||
|
|
||||||
|
* ext/md5/md5init.c (sha1_new): ditto.
|
||||||
|
|
||||||
Fri May 25 00:53:41 2001 Akinori MUSHA <knu@iDaemons.org>
|
Fri May 25 00:53:41 2001 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* ext/dbm/extconf.rb: fix support for *BSD and set $CFLAGS
|
* ext/dbm/extconf.rb: fix support for *BSD and set $CFLAGS
|
||||||
|
|
|
@ -75,21 +75,33 @@ md5i_clone(obj)
|
||||||
return obj;
|
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
|
static VALUE
|
||||||
md5i_new(argc, argv, class)
|
md5i_new(argc, argv, class)
|
||||||
int argc;
|
int argc;
|
||||||
VALUE* argv;
|
VALUE* argv;
|
||||||
VALUE class;
|
VALUE class;
|
||||||
{
|
{
|
||||||
VALUE obj, str;
|
VALUE obj;
|
||||||
md5_state_t *md5;
|
md5_state_t *md5;
|
||||||
|
|
||||||
obj = Data_Make_Struct(class, md5_state_t, 0, free, md5);
|
obj = Data_Make_Struct(class, md5_state_t, 0, free, md5);
|
||||||
md5_init(md5);
|
md5_init(md5);
|
||||||
rb_scan_args(argc, argv, "01", &str);
|
rb_obj_call_init(obj, argc, argv);
|
||||||
if (argc == 1) {
|
|
||||||
md5i_update(obj, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -102,6 +114,7 @@ Init_md5()
|
||||||
rb_define_singleton_method(cMD5, "new", md5i_new, -1);
|
rb_define_singleton_method(cMD5, "new", md5i_new, -1);
|
||||||
rb_define_singleton_method(cMD5, "md5", 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, "update", md5i_update, 1);
|
||||||
rb_define_method(cMD5, "<<", md5i_update, 1);
|
rb_define_method(cMD5, "<<", md5i_update, 1);
|
||||||
rb_define_method(cMD5, "digest", md5i_digest, 0);
|
rb_define_method(cMD5, "digest", md5i_digest, 0);
|
||||||
|
|
|
@ -63,23 +63,33 @@ sha1_clone(obj)
|
||||||
return obj;
|
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
|
static VALUE
|
||||||
sha1_new(argc, argv, class)
|
sha1_new(argc, argv, class)
|
||||||
int argc;
|
int argc;
|
||||||
VALUE* argv;
|
VALUE* argv;
|
||||||
VALUE class;
|
VALUE class;
|
||||||
{
|
{
|
||||||
VALUE arg, obj;
|
VALUE obj;
|
||||||
SHA1_CTX *sha1;
|
SHA1_CTX *sha1;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", &arg);
|
|
||||||
if (!NIL_P(arg)) Check_Type(arg, T_STRING);
|
|
||||||
|
|
||||||
obj = Data_Make_Struct(class, SHA1_CTX, 0, free, sha1);
|
obj = Data_Make_Struct(class, SHA1_CTX, 0, free, sha1);
|
||||||
SHA1Init(sha1);
|
SHA1Init(sha1);
|
||||||
if (!NIL_P(arg)) {
|
rb_obj_call_init(obj, argc, argv);
|
||||||
sha1_update(obj, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +103,7 @@ Init_sha1()
|
||||||
rb_define_singleton_method(cSHA1, "sha1", sha1_new, -1);
|
rb_define_singleton_method(cSHA1, "sha1", sha1_new, -1);
|
||||||
|
|
||||||
rb_define_method(cSHA1, "update", sha1_update, 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, "<<", sha1_update, 1);
|
||||||
rb_define_method(cSHA1, "digest", sha1_digest, 0);
|
rb_define_method(cSHA1, "digest", sha1_digest, 0);
|
||||||
rb_define_method(cSHA1, "hexdigest", sha1_hexdigest, 0);
|
rb_define_method(cSHA1, "hexdigest", sha1_hexdigest, 0);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче