Ruby: ext/digest/digest.h Source File

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

digest.h
Go to the documentation of this file.
1/************************************************
2
3 digest.h - header file for ruby digest modules
4
5 $Author$
6 created at: Fri May 25 08:54:56 JST 2001
7
8
9 Copyright (C) 2001-2006 Akinori MUSHA
10
11 $RoughId: digest.h,v 1.3 2001/07/13 15:38:27 knu Exp $
12 $Id$
13
14************************************************/
15
16#include "ruby.h"
17
18#define RUBY_DIGEST_API_VERSION 3
19
20 typedef int (*rb_digest_hash_init_func_t)(void *);
21 typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
22 typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
23
24 typedef struct {
25 int api_version;
26 size_t digest_len;
27 size_t block_len;
28 size_t ctx_size;
29 rb_digest_hash_init_func_t init_func;
30 rb_digest_hash_update_func_t update_func;
31 rb_digest_hash_finish_func_t finish_func;
32} rb_digest_metadata_t;
33
34#define DEFINE_UPDATE_FUNC_FOR_UINT(name) \
35void \
36rb_digest_##name##_update(void *ctx, unsigned char *ptr, size_t size) \
37{ \
38 const unsigned int stride = 16384; \
39 \
40 for (; size > stride; size -= stride, ptr += stride) { \
41 name##_Update(ctx, ptr, stride); \
42 } \
43 if (size > 0) name##_Update(ctx, ptr, size); \
44}
45
46#define DEFINE_FINISH_FUNC_FROM_FINAL(name) \
47int \
48rb_digest_##name##_finish(void *ctx, unsigned char *ptr) \
49{ \
50 return name##_Final(ptr, ctx); \
51}
52
53static inline VALUE
54rb_digest_namespace(void)
55{
56 rb_require("digest");
57 return rb_path2class("Digest");
58}
59
60static inline ID
61rb_id_metadata(void)
62{
63 return rb_intern_const("metadata");
64}
65
66static inline VALUE
67rb_digest_make_metadata(const rb_digest_metadata_t *meta)
68{
69#undef RUBY_UNTYPED_DATA_WARNING
70#define RUBY_UNTYPED_DATA_WARNING 0
71 return rb_obj_freeze(Data_Wrap_Struct(0, 0, 0, (void *)meta));
72}
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_obj_freeze
VALUE rb_obj_freeze(VALUE)
Make the object unmodifiable.
Definition: object.c:1101
rb_path2class
VALUE rb_path2class(const char *)
Definition: variable.c:287
int
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
Data_Wrap_Struct
#define Data_Wrap_Struct(klass, mark, free, sval)
Definition: rdata.h:80
ruby.h
rb_require
VALUE rb_require(const char *)
Definition: load.c:1199
rb_digest_metadata_t
Definition: digest.h:24
rb_digest_metadata_t::block_len
size_t block_len
Definition: digest.h:27
rb_digest_metadata_t::api_version
int api_version
Definition: digest.h:25
rb_digest_metadata_t::init_func
rb_digest_hash_init_func_t init_func
Definition: digest.h:29
rb_digest_metadata_t::digest_len
size_t digest_len
Definition: digest.h:26
rb_digest_metadata_t::ctx_size
size_t ctx_size
Definition: digest.h:28
rb_digest_metadata_t::finish_func
rb_digest_hash_finish_func_t finish_func
Definition: digest.h:31
rb_digest_metadata_t::update_func
rb_digest_hash_update_func_t update_func
Definition: digest.h:30
VALUE
unsigned long VALUE
Definition: value.h:38
ID
unsigned long ID
Definition: value.h:39