Skip to content

Commit d39b684

Browse files
committed
[DOC] Expand Digest::SHA2 definitions for RDoc
Since RDoc searches `var = rb_define_class_under(...)` statements literally, they cannot be built by macros.
1 parent e5d3039 commit d39b684

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

ext/digest/sha2/sha2init.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,50 @@ static const rb_digest_metadata_t sha##bitlen = { \
2525
FOREACH_BITLEN(DEFINE_ALGO_METADATA)
2626

2727
/*
28+
* Document-class: Digest::SHA256 < Digest::Base
29+
*
2830
* Classes for calculating message digests using the SHA-256/384/512
2931
* Secure Hash Algorithm(s) by NIST (the US' National Institute of
3032
* Standards and Technology), described in FIPS PUB 180-2.
33+
*
34+
* See SHA2.
35+
*/
36+
/*
37+
* Document-class: Digest::SHA384 < Digest::Base
38+
*
39+
* Classes for calculating message digests using the SHA-256/384/512
40+
* Secure Hash Algorithm(s) by NIST (the US' National Institute of
41+
* Standards and Technology), described in FIPS PUB 180-2.
42+
*
43+
* See SHA2.
44+
*/
45+
/*
46+
* Document-class: Digest::SHA512 < Digest::Base
47+
*
48+
* Classes for calculating message digests using the SHA-256/384/512
49+
* Secure Hash Algorithm(s) by NIST (the US' National Institute of
50+
* Standards and Technology), described in FIPS PUB 180-2.
51+
*
52+
* See SHA2.
3153
*/
3254
void
3355
Init_sha2(void)
3456
{
35-
VALUE mDigest, cDigest_Base;
57+
VALUE mDigest, cDigest_Base, cDigest_SHA2;
3658
ID id_metadata = rb_id_metadata();
3759

38-
#define DECLARE_ALGO_CLASS(bitlen) \
39-
VALUE cDigest_SHA##bitlen;
40-
41-
FOREACH_BITLEN(DECLARE_ALGO_CLASS)
42-
4360
#if 0
4461
mDigest = rb_define_module("Digest"); /* let rdoc know */
4562
#endif
4663
mDigest = rb_digest_namespace();
4764
cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
4865

49-
#define DEFINE_ALGO_CLASS(bitlen) \
50-
cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
51-
\
52-
rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
53-
rb_digest_make_metadata(&sha##bitlen));
66+
cDigest_SHA2 = rb_define_class_under(mDigest, "SHA256", cDigest_Base);
67+
rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha256));
68+
69+
cDigest_SHA2 = rb_define_class_under(mDigest, "SHA384", cDigest_Base);
70+
rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha384));
5471

55-
FOREACH_BITLEN(DEFINE_ALGO_CLASS)
72+
cDigest_SHA2 = rb_define_class_under(mDigest, "SHA512", cDigest_Base);
73+
rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha512));
5674
}

0 commit comments

Comments
 (0)