Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .document
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LICENSE.txt
README.md
ext/digest/
lib/digest.rb
lib/digest/sha2.rb
7 changes: 4 additions & 3 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand Down
3 changes: 3 additions & 0 deletions ext/digest/.document
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
digest.c
bubblebabble/bubblebabble.c
*/*init.c
7 changes: 3 additions & 4 deletions ext/digest/bubblebabble/bubblebabble.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ Init_bubblebabble(void)

rb_require("digest");

rb_mDigest = rb_path2class("Digest");
rb_mDigest_Instance = rb_path2class("Digest::Instance");
rb_cDigest_Class = rb_path2class("Digest::Class");

#if 0
rb_mDigest = rb_define_module("Digest");
rb_mDigest_Instance = rb_define_module_under(rb_mDigest, "Instance");
rb_cDigest_Class = rb_define_class_under(rb_mDigest, "Class", rb_cObject);
#endif
rb_mDigest = rb_digest_namespace();
rb_mDigest_Instance = rb_const_get(rb_mDigest, rb_intern_const("Instance"));
rb_cDigest_Class = rb_const_get(rb_mDigest, rb_intern_const("Class"));

rb_define_module_function(rb_mDigest, "bubblebabble", rb_digest_s_bubblebabble, 1);
rb_define_singleton_method(rb_cDigest_Class, "bubblebabble", rb_digest_class_s_bubblebabble, -1);
Expand Down
3 changes: 1 addition & 2 deletions ext/digest/md5/md5init.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ Init_md5(void)
mDigest = rb_define_module("Digest"); /* let rdoc know */
#endif
mDigest = rb_digest_namespace();
cDigest_Base = rb_path2class("Digest::Base");
cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));

cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base);

rb_iv_set(cDigest_MD5, "metadata", rb_digest_make_metadata(&md5));
}
3 changes: 1 addition & 2 deletions ext/digest/rmd160/rmd160init.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ Init_rmd160(void)
mDigest = rb_define_module("Digest"); /* let rdoc know */
#endif
mDigest = rb_digest_namespace();
cDigest_Base = rb_path2class("Digest::Base");
cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));

cDigest_RMD160 = rb_define_class_under(mDigest, "RMD160", cDigest_Base);

rb_iv_set(cDigest_RMD160, "metadata", rb_digest_make_metadata(&rmd160));
}
3 changes: 1 addition & 2 deletions ext/digest/sha1/sha1init.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ Init_sha1(void)
mDigest = rb_define_module("Digest"); /* let rdoc know */
#endif
mDigest = rb_digest_namespace();
cDigest_Base = rb_path2class("Digest::Base");
cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));

cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);

rb_iv_set(cDigest_SHA1, "metadata", rb_digest_make_metadata(&sha1));
}
47 changes: 34 additions & 13 deletions ext/digest/sha2/sha2init.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,50 @@ static const rb_digest_metadata_t sha##bitlen = { \
FOREACH_BITLEN(DEFINE_ALGO_METADATA)

/*
* Document-class: Digest::SHA256 < Digest::Base
*
* Classes for calculating message digests using the SHA-256/384/512
* Secure Hash Algorithm(s) by NIST (the US' National Institute of
* Standards and Technology), described in FIPS PUB 180-2.
*
* See SHA2.
*/
/*
* Document-class: Digest::SHA384 < Digest::Base
*
* Classes for calculating message digests using the SHA-256/384/512
* Secure Hash Algorithm(s) by NIST (the US' National Institute of
* Standards and Technology), described in FIPS PUB 180-2.
*
* See SHA2.
*/
/*
* Document-class: Digest::SHA512 < Digest::Base
*
* Classes for calculating message digests using the SHA-256/384/512
* Secure Hash Algorithm(s) by NIST (the US' National Institute of
* Standards and Technology), described in FIPS PUB 180-2.
*
* See SHA2.
*/
void
Init_sha2(void)
{
VALUE mDigest, cDigest_Base;
VALUE mDigest, cDigest_Base, cDigest_SHA2;
ID id_metadata = rb_id_metadata();

#define DECLARE_ALGO_CLASS(bitlen) \
VALUE cDigest_SHA##bitlen;

FOREACH_BITLEN(DECLARE_ALGO_CLASS)

#if 0
mDigest = rb_define_module("Digest"); /* let rdoc know */
#endif
mDigest = rb_digest_namespace();
cDigest_Base = rb_path2class("Digest::Base");
cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));

cDigest_SHA2 = rb_define_class_under(mDigest, "SHA256", cDigest_Base);
rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha256));

#define DEFINE_ALGO_CLASS(bitlen) \
cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
\
rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
rb_digest_make_metadata(&sha##bitlen));
cDigest_SHA2 = rb_define_class_under(mDigest, "SHA384", cDigest_Base);
rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha384));

FOREACH_BITLEN(DEFINE_ALGO_CLASS)
cDigest_SHA2 = rb_define_class_under(mDigest, "SHA512", cDigest_Base);
rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha512));
}