Ruby: ext/digest/md5/md5init.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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
12static const rb_digest_metadata_t md5 = {
13 RUBY_DIGEST_API_VERSION,
14 MD5_DIGEST_LENGTH,
15 MD5_BLOCK_LENGTH,
16 sizeof(MD5_CTX),
17 (rb_digest_hash_init_func_t)MD5_Init,
18 (rb_digest_hash_update_func_t)MD5_Update,
19 (rb_digest_hash_finish_func_t)MD5_Finish,
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 */
47void
48Init_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}
RUBY_DIGEST_API_VERSION
#define RUBY_DIGEST_API_VERSION
Definition: digest.h:18
rb_digest_hash_update_func_t
void(* rb_digest_hash_update_func_t)(void *, unsigned char *, size_t)
Definition: digest.h:21
rb_digest_hash_init_func_t
int(* rb_digest_hash_init_func_t)(void *)
Definition: digest.h:20
rb_digest_hash_finish_func_t
int(* rb_digest_hash_finish_func_t)(void *, unsigned char *)
Definition: digest.h:22
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:797
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:871
rb_path2class
VALUE rb_path2class(const char *)
Definition: variable.c:287
rb_iv_set
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:3580
md5.h
MD5_DIGEST_LENGTH
#define MD5_DIGEST_LENGTH
Definition: md5.h:77
MD5_BLOCK_LENGTH
#define MD5_BLOCK_LENGTH
Definition: md5.h:76
MD5_CTX
struct md5_state_s MD5_CTX
MD5_Init
#define MD5_Init
Definition: md5.h:67
MD5_Finish
#define MD5_Finish
Definition: md5.h:69
MD5_Update
#define MD5_Update
Definition: md5.h:68
md5cc.h
Init_md5
void Init_md5(void)
Definition: md5init.c:48
ruby.h
rb_digest_metadata_t
Definition: digest.h:24
VALUE
unsigned long VALUE
Definition: value.h:38