Ruby  3.1.0dev(2021-09-10revisionb76ad15ed0da636161de0243c547ee1e6fc95681)
md5init.c
Go to the documentation of this file.
1 /* $RoughId: md5init.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */
2 /* $Id$ */
3 
4 #include <ruby/ruby.h>
5 #include "../digest.h"
6 #if defined(MD5_USE_COMMONDIGEST)
7 #include "md5cc.h"
8 #else
9 #include "md5.h"
10 #endif
11 
12 static const rb_digest_metadata_t md5 = {
16  sizeof(MD5_CTX),
20 };
21 
22 /*
23  * Document-class: Digest::MD5 < Digest::Base
24  * A class for calculating message digests using the MD5
25  * Message-Digest Algorithm by RSA Data Security, Inc., described in
26  * RFC1321.
27  *
28  * MD5 calculates a digest of 128 bits (16 bytes).
29  *
30  * == Examples
31  * require 'digest'
32  *
33  * # Compute a complete digest
34  * Digest::MD5.hexdigest 'abc' #=> "90015098..."
35  *
36  * # Compute digest by chunks
37  * md5 = Digest::MD5.new # =>#<Digest::MD5>
38  * md5.update "ab"
39  * md5 << "c" # alias for #update
40  * md5.hexdigest # => "90015098..."
41  *
42  * # Use the same object to compute another digest
43  * md5.reset
44  * md5 << "message"
45  * md5.hexdigest # => "78e73102..."
46  */
47 void
48 Init_md5(void)
49 {
50  VALUE mDigest, cDigest_Base, cDigest_MD5;
51 
52 #if 0
53  mDigest = rb_define_module("Digest"); /* let rdoc know */
54 #endif
55  mDigest = rb_digest_namespace();
56  cDigest_Base = rb_path2class("Digest::Base");
57 
58  cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base);
59 
60  rb_iv_set(cDigest_MD5, "metadata", rb_digest_make_metadata(&md5));
61 }
rb_digest_hash_finish_func_t
int(* rb_digest_hash_finish_func_t)(void *, unsigned char *)
Definition: digest.h:22
md5cc.h
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:887
ruby.h
Init_md5
void Init_md5(void)
Definition: md5init.c:48
rb_iv_set
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:3670
MD5_Init
int MD5_Init(MD5_CTX *pms)
Definition: md5.c:354
RUBY_DIGEST_API_VERSION
#define RUBY_DIGEST_API_VERSION
Definition: digest.h:18
rb_digest_metadata_t
Definition: digest.h:24
VALUE
unsigned long VALUE
Definition: value.h:38
MD5_Update
void MD5_Update(MD5_CTX *pms, const uint8_t *data, size_t nbytes)
Definition: md5.c:365
md5.h
MD5_DIGEST_LENGTH
#define MD5_DIGEST_LENGTH
Definition: md5.h:77
rb_digest_hash_init_func_t
int(* rb_digest_hash_init_func_t)(void *)
Definition: digest.h:20
rb_path2class
VALUE rb_path2class(const char *)
Definition: variable.c:289
MD5_BLOCK_LENGTH
#define MD5_BLOCK_LENGTH
Definition: md5.h:76
MD5_Finish
int MD5_Finish(MD5_CTX *pms, uint8_t *digest)
Definition: md5.c:403
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:809
rb_digest_hash_update_func_t
void(* rb_digest_hash_update_func_t)(void *, unsigned char *, size_t)
Definition: digest.h:21
MD5_CTX
struct md5_state_s MD5_CTX