From 9278714fac9c7b1f0220700f14f257563c1e180f Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sun, 29 Dec 2024 16:38:36 +0100 Subject: [PATCH] Fix compatibility with newer digest gems (#29) Fix: https://github.com/q9f/keccak.rb/issues/27 Ref: https://github.com/ruby/digest/pull/58 Ref: https://github.com/ruby/digest/pull/59 --- .gitignore | 2 ++ ext/digest/extconf.rb | 1 + ext/digest/keccak.c | 4 ++++ 3 files changed, 7 insertions(+) mode change 100644 => 100755 ext/digest/extconf.rb diff --git a/.gitignore b/.gitignore index 6abceb8..553e61e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ *.gem *.log *.rbc +*.bundle +*.bundle.dSYM /.config /.rake_tasks~ /coverage/ diff --git a/ext/digest/extconf.rb b/ext/digest/extconf.rb old mode 100644 new mode 100755 index 5e90454..c26f730 --- a/ext/digest/extconf.rb +++ b/ext/digest/extconf.rb @@ -27,5 +27,6 @@ def have_func!(header, *args) have_header! "string.h" have_func! "rb_str_set_len" +have_func "rb_digest_make_metadata", "ruby/digest.h" create_makefile "digest/keccak" or exit 1 diff --git a/ext/digest/keccak.c b/ext/digest/keccak.c index 981f002..0c31d67 100644 --- a/ext/digest/keccak.c +++ b/ext/digest/keccak.c @@ -144,7 +144,11 @@ Init_keccak() { cKeccak = rb_define_class_under(mDigest, "Keccak", cDigest_Base); +#ifdef HAVE_RB_DIGEST_MAKE_METADATA + rb_iv_set(cKeccak, "metadata", rb_digest_make_metadata(&keccak)); +#else rb_iv_set(cKeccak, "metadata", Data_Wrap_Struct(0, 0, 0, (void *)&keccak)); +#endif rb_define_method(cKeccak, "initialize", rb_keccak_initialize, -1); rb_define_method(cKeccak, "digest_length", rb_keccak_digest_length, 0);