Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

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_OPENSSL)
7 #include "md5ossl.h"
8 #elif defined(MD5_USE_COMMONDIGEST)
9 #include "md5cc.h"
10 #else
11 #include "md5.h"
12 #endif
13
14 static const rb_digest_metadata_t md5 = {
15 RUBY_DIGEST_API_VERSION,
16 MD5_DIGEST_LENGTH,
17 MD5_BLOCK_LENGTH,
18 sizeof(MD5_CTX),
19 (rb_digest_hash_init_func_t)MD5_Init,
20 (rb_digest_hash_update_func_t)MD5_Update,
21 (rb_digest_hash_finish_func_t)MD5_Finish,
22 };
23
24 /*
25 * Document-class: Digest::MD5 < Digest::Base
26 * A class for calculating message digests using the MD5
27 * Message-Digest Algorithm by RSA Data Security, Inc., described in
28 * RFC1321.
29 *
30 * MD5 calculates a digest of 128 bits (16 bytes).
31 *
32 * == Examples
33 * require 'digest'
34 *
35 * # Compute a complete digest
36 * Digest::MD5.hexdigest 'abc' #=> "90015098..."
37 *
38 * # Compute digest by chunks
39 * md5 = Digest::MD5.new # =>#<Digest::MD5>
40 * md5.update "ab"
41 * md5 << "c" # alias for #update
42 * md5.hexdigest # => "90015098..."
43 *
44 * # Use the same object to compute another digest
45 * md5.reset
46 * md5 << "message"
47 * md5.hexdigest # => "78e73102..."
48 */
49 void
50 Init_md5(void)
51 {
52 VALUE mDigest, cDigest_Base, cDigest_MD5;
53
54 #if 0
55 mDigest = rb_define_module("Digest"); /* let rdoc know */
56 #endif
57 mDigest = rb_digest_namespace();
58 cDigest_Base = rb_path2class("Digest::Base");
59
60 cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base);
61
62 #undef RUBY_UNTYPED_DATA_WARNING
63 #define RUBY_UNTYPED_DATA_WARNING 0
64 rb_iv_set(cDigest_MD5, "metadata",
65 Data_Wrap_Struct(0, 0, 0, (void *)&md5));
66 }
rb_digest_hash_finish_func_t
int(* rb_digest_hash_finish_func_t)(void *, unsigned char *)
Definition: digest.h:22
md5ossl.h
md5cc.h
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:772
Data_Wrap_Struct
#define Data_Wrap_Struct(klass, mark, free, sval)
Definition: ruby.h:1211
ruby.h
Init_md5
void Init_md5(void)
Definition: md5init.c:50
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
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:268
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:698
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
rb_iv_set
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:3307