18 static VALUE rb_mDigest;
19 static VALUE rb_mDigest_Instance;
20 static VALUE rb_cDigest_Class;
21 static VALUE rb_cDigest_Base;
23 static ID id_reset, id_update, id_finish, id_digest, id_hexdigest, id_digest_length;
24 static ID id_metadata;
98 hexencode_str_new(
VALUE str_digest)
105 static const char hex[] = {
106 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
107 'a',
'b',
'c',
'd',
'e',
'f' 120 for (i = 0, p =
RSTRING_PTR(str); i < digest_len; i++) {
121 unsigned char byte = digest[i];
123 p[i + i] = hex[byte >> 4];
124 p[i + i + 1] = hex[byte & 0x0f];
141 return hexencode_str_new(str);
144 NORETURN(
static void rb_digest_instance_method_unimpl(
VALUE self,
const char *method));
154 rb_digest_instance_method_unimpl(
VALUE self,
const char *method)
172 rb_digest_instance_update(
VALUE self,
VALUE str)
174 rb_digest_instance_method_unimpl(
self,
"update");
192 rb_digest_instance_finish(
VALUE self)
194 rb_digest_instance_method_unimpl(
self,
"finish");
208 rb_digest_instance_reset(
VALUE self)
210 rb_digest_instance_method_unimpl(
self,
"reset");
223 rb_digest_instance_new(
VALUE self)
267 rb_digest_instance_digest_bang(
VALUE self)
288 rb_digest_instance_hexdigest(
int argc,
VALUE *argv,
VALUE self)
301 return hexencode_str_new(value);
312 rb_digest_instance_hexdigest_bang(
VALUE self)
317 return hexencode_str_new(value);
327 rb_digest_instance_to_s(
VALUE self)
339 rb_digest_instance_inspect(
VALUE self)
342 size_t digest_len = 32;
368 rb_digest_instance_equal(
VALUE self,
VALUE other)
373 str1 = rb_digest_instance_digest(0, 0,
self);
374 str2 = rb_digest_instance_digest(0, 0, other);
376 str1 = rb_digest_instance_to_s(
self);
402 rb_digest_instance_digest_length(
VALUE self)
405 VALUE digest = rb_digest_instance_digest(0, 0,
self);
420 rb_digest_instance_length(
VALUE self)
434 rb_digest_instance_block_length(
VALUE self)
436 rb_digest_instance_method_unimpl(
self,
"block_length");
458 rb_digest_class_s_digest(
int argc,
VALUE *argv,
VALUE klass)
487 rb_digest_class_s_hexdigest(
int argc,
VALUE *argv,
VALUE klass)
489 return hexencode_str_new(
rb_funcallv(klass, id_digest, argc, argv));
494 rb_digest_class_init(
VALUE self)
541 get_digest_base_metadata(
VALUE klass)
557 #undef RUBY_UNTYPED_DATA_WARNING 558 #define RUBY_UNTYPED_DATA_WARNING 0 592 rb_digest_base_alloc(
VALUE klass)
598 if (klass == rb_cDigest_Base) {
602 algo = get_digest_base_metadata(klass);
606 algo_init(algo, pctx);
618 if (copy == obj)
return copy;
623 if (algo != get_digest_base_metadata(
rb_obj_class(obj)))
628 memcpy(pctx2, pctx1, algo->
ctx_size);
639 rb_digest_base_reset(
VALUE self)
648 algo_init(algo, pctx);
679 rb_digest_base_finish(
VALUE self)
693 algo_init(algo, pctx);
704 rb_digest_base_digest_length(
VALUE self)
719 rb_digest_base_block_length(
VALUE self)
736 id_digest_length =
rb_intern(
"digest_length");
752 rb_define_method(rb_mDigest_Instance,
"update", rb_digest_instance_update, 1);
755 rb_define_method(rb_mDigest_Instance,
"reset", rb_digest_instance_reset, 0);
756 rb_define_method(rb_mDigest_Instance,
"digest_length", rb_digest_instance_digest_length, 0);
757 rb_define_method(rb_mDigest_Instance,
"block_length", rb_digest_instance_block_length, 0);
761 rb_define_method(rb_mDigest_Instance,
"inspect", rb_digest_instance_inspect, 0);
765 rb_define_method(rb_mDigest_Instance,
"digest", rb_digest_instance_digest, -1);
766 rb_define_method(rb_mDigest_Instance,
"digest!", rb_digest_instance_digest_bang, 0);
767 rb_define_method(rb_mDigest_Instance,
"hexdigest", rb_digest_instance_hexdigest, -1);
768 rb_define_method(rb_mDigest_Instance,
"hexdigest!", rb_digest_instance_hexdigest_bang, 0);
770 rb_define_method(rb_mDigest_Instance,
"length", rb_digest_instance_length, 0);
771 rb_define_method(rb_mDigest_Instance,
"size", rb_digest_instance_length, 0);
791 rb_define_method(rb_cDigest_Base,
"initialize_copy", rb_digest_base_copy, 1);
796 rb_define_method(rb_cDigest_Base,
"digest_length", rb_digest_base_digest_length, 0);
797 rb_define_method(rb_cDigest_Base,
"block_length", rb_digest_base_block_length, 0);
#define RUBY_TYPED_FREE_IMMEDIATELY
size_t strlen(const char *)
#define Data_Get_Struct(obj, type, sval)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
void rb_raise(VALUE exc, const char *fmt,...)
#define TypedData_Get_Struct(obj, type, data_type, sval)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_ivar_get(VALUE, ID)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
void rb_include_module(VALUE klass, VALUE module)
int rb_str_cmp(VALUE, VALUE)
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv)
Calls #initialize method of obj with the given arguments.
VALUE rb_str_buf_append(VALUE, VALUE)
VALUE rb_ivar_defined(VALUE, ID)
const char * rb_obj_classname(VALUE)
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
VALUE rb_obj_is_kind_of(VALUE, VALUE)
call-seq: obj.is_a?(class) -> true or false obj.kind_of?(class) -> true or false
#define RUBY_TYPED_WB_PROTECTED
NORETURN(static void rb_digest_instance_method_unimpl(VALUE self, const char *method))
RUBY_EXTERN VALUE rb_cObject
VALUE rb_str_buf_cat2(VALUE, const char *)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_define_module_under(VALUE outer, const char *name)
VALUE rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type)
VALUE rb_class_superclass(VALUE)
call-seq: class.superclass -> a_super_class or nil
VALUE rb_check_string_type(VALUE)
#define RTYPEDDATA_DATA(v)
#define rb_check_frozen(obj)
#define RUBY_TYPED_DEFAULT_FREE
RUBY_EXTERN void Init_digest_base(void)
VALUE rb_define_module(const char *name)
VALUE rb_str_buf_new(long)
VALUE rb_usascii_str_new(const char *, long)
VALUE rb_obj_clone(VALUE)
:nodoc Almost same as Object::clone ++
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new(const char *, long)