digest 3.1.1 → 3.2.0.pre0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 987de45a2894fa80f0d6ff23f3a70a7e813b9529b5ef4130b22be5e4c2f78020
4
- data.tar.gz: 7241f2a350845b1478666dfbb0d6662a1b61e41a16e7504b064dd6eca6e3c0b2
3
+ metadata.gz: b483eb57905b2f3160885f8ed98050921b9b3e13005ddfdc5af7247f0c80941e
4
+ data.tar.gz: 5d2e8f21b545eba60d48fc2b1a8799f46f12ae5740257fef5d956843e6f285df
5
5
  SHA512:
6
- metadata.gz: b1f322b8fed96de4cde9b2b8cd2997f99a80998b5b671924cb6f3e3b6b28215c95021f2919ef8a5176823639e56ddb3cd05e2a154c59d9945f4770138ae4d941
7
- data.tar.gz: f2a9f6d45f28fe9be2d140d9f99147669f9a0ab32fbeac724254eca036a89a364f222beac6eb3b38def4f395f961dc646a7780344e7eb13eff0759a39b7c6ce7
6
+ metadata.gz: 0aebec72ac962b1ba44caad93e6df25076ae0622955f5cfdb068379919a2aa5aae85ef5cbe3ab186a0bbbd1bd0242cb47d4fb6406fd5fad0894fef77ed95d121
7
+ data.tar.gz: 615ebcf317c30885746bdd75b3d6c1c681036f2282ba912cdb2ff1eae5086d1460f37fc3fa7ae9f6dd9e9b2be9ee0be7ebe6fa276b0fb7acd73ce2ae250a1a1f
data/LICENSE.txt CHANGED
@@ -4,10 +4,11 @@ Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
5
5
  are met:
6
6
  1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
7
+ notice, this list of conditions and the following disclaimer.
8
8
  2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the
11
+ distribution.
11
12
 
12
13
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
14
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
data/README.md CHANGED
@@ -82,6 +82,16 @@ SHA2 family::
82
82
 
83
83
  The latest versions of the FIPS publications can be found here: http://csrc.nist.gov/publications/PubsFIPS.html.
84
84
 
85
+ ## For Gem developers
86
+
87
+ If you want to use digest algorithms in your C extension, you can use the `digest.h` header file provided by digest gem. You should add the following code to your `extconf.rb`:
88
+
89
+ ```ruby
90
+ spec = Gem::Specification.find_by_name("digest")
91
+ source_dir = File.join(spec.full_gem_path, "ext", "digest")
92
+ $INCFLAGS += " -I#{source_dir}"
93
+ ```
94
+
85
95
  ## Development
86
96
 
87
97
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -129,15 +129,14 @@ Init_bubblebabble(void)
129
129
 
130
130
  rb_require("digest");
131
131
 
132
- rb_mDigest = rb_path2class("Digest");
133
- rb_mDigest_Instance = rb_path2class("Digest::Instance");
134
- rb_cDigest_Class = rb_path2class("Digest::Class");
135
-
136
132
  #if 0
137
133
  rb_mDigest = rb_define_module("Digest");
138
134
  rb_mDigest_Instance = rb_define_module_under(rb_mDigest, "Instance");
139
135
  rb_cDigest_Class = rb_define_class_under(rb_mDigest, "Class", rb_cObject);
140
136
  #endif
137
+ rb_mDigest = rb_digest_namespace();
138
+ rb_mDigest_Instance = rb_const_get(rb_mDigest, rb_intern_const("Instance"));
139
+ rb_cDigest_Class = rb_const_get(rb_mDigest, rb_intern_const("Class"));
141
140
 
142
141
  rb_define_module_function(rb_mDigest, "bubblebabble", rb_digest_s_bubblebabble, 1);
143
142
  rb_define_singleton_method(rb_cDigest_Class, "bubblebabble", rb_digest_class_s_bubblebabble, -1);
data/ext/digest/digest.c CHANGED
@@ -534,9 +534,39 @@ rb_digest_class_init(VALUE self)
534
534
  *
535
535
  *
536
536
  * rb_ivar_set(cDigest_SHA1, rb_intern("metadata"),
537
- * Data_Wrap_Struct(0, 0, 0, (void *)&sha1));
537
+ * rb_digest_make_metadata(&sha1));
538
538
  */
539
539
 
540
+ #ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
541
+ static const rb_data_type_t metadata_type = {
542
+ "digest/metadata",
543
+ {0},
544
+ };
545
+
546
+ RUBY_FUNC_EXPORTED VALUE
547
+ rb_digest_wrap_metadata(const rb_digest_metadata_t *meta)
548
+ {
549
+ return rb_obj_freeze(TypedData_Wrap_Struct(0, &metadata_type, (void *)meta));
550
+ }
551
+ #endif
552
+
553
+ static rb_digest_metadata_t *
554
+ get_metadata_ptr(VALUE obj)
555
+ {
556
+ rb_digest_metadata_t *algo;
557
+
558
+ #ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
559
+ if (!rb_typeddata_is_kind_of(obj, &metadata_type)) return 0;
560
+ algo = RTYPEDDATA_DATA(obj);
561
+ #else
562
+ # undef RUBY_UNTYPED_DATA_WARNING
563
+ # define RUBY_UNTYPED_DATA_WARNING 0
564
+ Data_Get_Struct(obj, rb_digest_metadata_t, algo);
565
+ #endif
566
+
567
+ return algo;
568
+ }
569
+
540
570
  static rb_digest_metadata_t *
541
571
  get_digest_base_metadata(VALUE klass)
542
572
  {
@@ -554,8 +584,8 @@ get_digest_base_metadata(VALUE klass)
554
584
  if (NIL_P(p))
555
585
  rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");
556
586
 
557
- if (!RB_TYPE_P(obj, T_DATA) || RTYPEDDATA_P(obj)) {
558
- wrong:
587
+ algo = get_metadata_ptr(obj);
588
+ if (!algo) {
559
589
  if (p == klass)
560
590
  rb_raise(rb_eTypeError, "%"PRIsVALUE"::metadata is not initialized properly",
561
591
  klass);
@@ -564,12 +594,6 @@ get_digest_base_metadata(VALUE klass)
564
594
  klass, p);
565
595
  }
566
596
 
567
- #undef RUBY_UNTYPED_DATA_WARNING
568
- #define RUBY_UNTYPED_DATA_WARNING 0
569
- Data_Get_Struct(obj, rb_digest_metadata_t, algo);
570
-
571
- if (!algo) goto wrong;
572
-
573
597
  switch (algo->api_version) {
574
598
  case 3:
575
599
  break;
data/ext/digest/digest.h CHANGED
@@ -40,7 +40,8 @@ rb_digest_##name##_update(void *ctx, unsigned char *ptr, size_t size) \
40
40
  for (; size > stride; size -= stride, ptr += stride) { \
41
41
  name##_Update(ctx, ptr, stride); \
42
42
  } \
43
- if (size > 0) name##_Update(ctx, ptr, size); \
43
+ /* Since size <= stride, size should fit into an unsigned int */ \
44
+ if (size > 0) name##_Update(ctx, ptr, (unsigned int)size); \
44
45
  }
45
46
 
46
47
  #define DEFINE_FINISH_FUNC_FROM_FINAL(name) \
@@ -63,10 +64,43 @@ rb_id_metadata(void)
63
64
  return rb_intern_const("metadata");
64
65
  }
65
66
 
67
+ #if !defined(HAVE_RB_EXT_RESOLVE_SYMBOL)
68
+ #elif !defined(RUBY_UNTYPED_DATA_WARNING)
69
+ # error RUBY_UNTYPED_DATA_WARNING is not defined
70
+ #elif RUBY_UNTYPED_DATA_WARNING
71
+ /* rb_ext_resolve_symbol() has been defined since Ruby 3.3, but digest
72
+ * bundled with 3.3 didn't use it. */
73
+ # define DIGEST_USE_RB_EXT_RESOLVE_SYMBOL 1
74
+ #endif
75
+
66
76
  static inline VALUE
67
77
  rb_digest_make_metadata(const rb_digest_metadata_t *meta)
68
78
  {
69
- #undef RUBY_UNTYPED_DATA_WARNING
70
- #define RUBY_UNTYPED_DATA_WARNING 0
79
+ #if defined(EXTSTATIC) && EXTSTATIC
80
+ /* The extension is built as a static library, so safe to refer to
81
+ * rb_digest_wrap_metadata directly. */
82
+ extern VALUE rb_digest_wrap_metadata(const rb_digest_metadata_t *meta);
83
+ return rb_digest_wrap_metadata(meta);
84
+ #else
85
+ /* The extension is built as a shared library, so we can't refer
86
+ * to rb_digest_wrap_metadata directly. */
87
+ # ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
88
+ /* If rb_ext_resolve_symbol() is available, use it to get the address of
89
+ * rb_digest_wrap_metadata. */
90
+ typedef VALUE (*wrapper_func_type)(const rb_digest_metadata_t *meta);
91
+ static wrapper_func_type wrapper;
92
+ if (!wrapper) {
93
+ wrapper = (wrapper_func_type)(uintptr_t)
94
+ rb_ext_resolve_symbol("digest.so", "rb_digest_wrap_metadata");
95
+ if (!wrapper) rb_raise(rb_eLoadError, "rb_digest_wrap_metadata not found");
96
+ }
97
+ return wrapper(meta);
98
+ # else
99
+ /* If rb_ext_resolve_symbol() is not available, keep using untyped
100
+ * data. */
101
+ # undef RUBY_UNTYPED_DATA_WARNING
102
+ # define RUBY_UNTYPED_DATA_WARNING 0
71
103
  return rb_obj_freeze(Data_Wrap_Struct(0, 0, 0, (void *)meta));
104
+ # endif
105
+ #endif
72
106
  }
@@ -1,8 +1,16 @@
1
1
  #define COMMON_DIGEST_FOR_OPENSSL 1
2
2
  #include <CommonCrypto/CommonDigest.h>
3
3
 
4
- #ifdef __clang__
5
- # pragma clang diagnostic ignored "-Wdeprecated-declarations"
4
+ #ifdef __GNUC__
5
+ # define RB_DIGEST_DIAGNOSTIC(compiler, op, flag) _Pragma(STRINGIZE(compiler diagnostic op flag))
6
+ # ifdef RBIMPL_WARNING_IGNORED
7
+ # define RB_DIGEST_WARNING_IGNORED(flag) RBIMPL_WARNING_IGNORED(flag)
8
+ # elif defined(__clang__)
9
+ # define RB_DIGEST_WARNING_IGNORED(flag) RB_DIGEST_DIAGNOSTIC(clang, ignored, #flag)
10
+ # else /* __GNUC__ */
11
+ # define RB_DIGEST_WARNING_IGNORED(flag) RB_DIGEST_DIAGNOSTIC(GCC, ignored, #flag)
12
+ # endif
13
+ RB_DIGEST_WARNING_IGNORED(-Wdeprecated-declarations)
6
14
  /* Suppress deprecation warnings of MD5 from Xcode 11.1 */
7
15
  /* Although we know MD5 is deprecated too, provide just for backward
8
16
  * compatibility, as well as Apple does. */
@@ -17,3 +25,11 @@ static DEFINE_FINISH_FUNC_FROM_FINAL(MD5)
17
25
  #undef MD5_Finish
18
26
  #define MD5_Update rb_digest_MD5_update
19
27
  #define MD5_Finish rb_digest_MD5_finish
28
+
29
+ /*
30
+ * Pre-10.6 defines are with args, which don't match the argless use in
31
+ * the function pointer inits. Thus, we redefine MD5_Init as well.
32
+ * This is a NOP on 10.6+.
33
+ */
34
+ #undef MD5_Init
35
+ #define MD5_Init CC_MD5_Init
@@ -53,9 +53,8 @@ Init_md5(void)
53
53
  mDigest = rb_define_module("Digest"); /* let rdoc know */
54
54
  #endif
55
55
  mDigest = rb_digest_namespace();
56
- cDigest_Base = rb_path2class("Digest::Base");
56
+ cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
57
57
 
58
58
  cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base);
59
-
60
59
  rb_iv_set(cDigest_MD5, "metadata", rb_digest_make_metadata(&md5));
61
60
  }
@@ -49,9 +49,8 @@ Init_rmd160(void)
49
49
  mDigest = rb_define_module("Digest"); /* let rdoc know */
50
50
  #endif
51
51
  mDigest = rb_digest_namespace();
52
- cDigest_Base = rb_path2class("Digest::Base");
52
+ cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
53
53
 
54
54
  cDigest_RMD160 = rb_define_class_under(mDigest, "RMD160", cDigest_Base);
55
-
56
55
  rb_iv_set(cDigest_RMD160, "metadata", rb_digest_make_metadata(&rmd160));
57
56
  }
@@ -12,3 +12,11 @@ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA1)
12
12
  #undef SHA1_Finish
13
13
  #define SHA1_Update rb_digest_SHA1_update
14
14
  #define SHA1_Finish rb_digest_SHA1_finish
15
+
16
+ /*
17
+ * Pre-10.6 defines are with args, which don't match the argless use in
18
+ * the function pointer inits. Thus, we redefine SHA1_Init as well.
19
+ * This is a NOP on 10.6+.
20
+ */
21
+ #undef SHA1_Init
22
+ #define SHA1_Init CC_SHA1_Init
@@ -55,9 +55,8 @@ Init_sha1(void)
55
55
  mDigest = rb_define_module("Digest"); /* let rdoc know */
56
56
  #endif
57
57
  mDigest = rb_digest_namespace();
58
- cDigest_Base = rb_path2class("Digest::Base");
58
+ cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
59
59
 
60
60
  cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);
61
-
62
61
  rb_iv_set(cDigest_SHA1, "metadata", rb_digest_make_metadata(&sha1));
63
62
  }
@@ -1,6 +1,33 @@
1
1
  #define COMMON_DIGEST_FOR_OPENSSL 1
2
2
  #include <CommonCrypto/CommonDigest.h>
3
3
 
4
+ /*
5
+ * Prior to 10.5, OpenSSL-compatible definitions are missing for
6
+ * SHA2 macros, though the CC_ versions are present.
7
+ * Add the missing definitions we actually use here if needed.
8
+ * Note that the definitions are the argless 10.6+-style.
9
+ * The weird CTX mismatch is copied from the 10.6 header.
10
+ */
11
+ #ifndef SHA256_DIGEST_LENGTH
12
+ #define SHA256_DIGEST_LENGTH CC_SHA256_DIGEST_LENGTH
13
+ #define SHA256_CTX CC_SHA256_CTX
14
+ #define SHA256_Update CC_SHA256_Update
15
+ #define SHA256_Final CC_SHA256_Final
16
+ #endif /* !defined SHA256_DIGEST_LENGTH */
17
+
18
+ #ifndef SHA384_DIGEST_LENGTH
19
+ #define SHA384_DIGEST_LENGTH CC_SHA384_DIGEST_LENGTH
20
+ #define SHA512_CTX CC_SHA512_CTX
21
+ #define SHA384_Update CC_SHA384_Update
22
+ #define SHA384_Final CC_SHA384_Final
23
+ #endif /* !defined SHA384_DIGEST_LENGTH */
24
+
25
+ #ifndef SHA512_DIGEST_LENGTH
26
+ #define SHA512_DIGEST_LENGTH CC_SHA512_DIGEST_LENGTH
27
+ #define SHA512_Update CC_SHA512_Update
28
+ #define SHA512_Final CC_SHA512_Final
29
+ #endif /* !defined SHA512_DIGEST_LENGTH */
30
+
4
31
  #define SHA256_BLOCK_LENGTH CC_SHA256_BLOCK_BYTES
5
32
  #define SHA384_BLOCK_LENGTH CC_SHA384_BLOCK_BYTES
6
33
  #define SHA512_BLOCK_LENGTH CC_SHA512_BLOCK_BYTES
@@ -29,3 +56,15 @@ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA512)
29
56
  #undef SHA512_Finish
30
57
  #define SHA512_Update rb_digest_SHA512_update
31
58
  #define SHA512_Finish rb_digest_SHA512_finish
59
+
60
+ /*
61
+ * Pre-10.6 defines are with args, which don't match the argless use in
62
+ * the function pointer inits. Thus, we redefine SHA*_Init as well.
63
+ * This is a NOP on 10.6+.
64
+ */
65
+ #undef SHA256_Init
66
+ #define SHA256_Init CC_SHA256_Init
67
+ #undef SHA384_Init
68
+ #define SHA384_Init CC_SHA384_Init
69
+ #undef SHA512_Init
70
+ #define SHA512_Init CC_SHA512_Init
@@ -25,29 +25,50 @@ static const rb_digest_metadata_t sha##bitlen = { \
25
25
  FOREACH_BITLEN(DEFINE_ALGO_METADATA)
26
26
 
27
27
  /*
28
+ * Document-class: Digest::SHA256 < Digest::Base
29
+ *
28
30
  * Classes for calculating message digests using the SHA-256/384/512
29
31
  * Secure Hash Algorithm(s) by NIST (the US' National Institute of
30
32
  * 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.
31
53
  */
32
54
  void
33
55
  Init_sha2(void)
34
56
  {
35
- VALUE mDigest, cDigest_Base;
57
+ VALUE mDigest, cDigest_Base, cDigest_SHA2;
36
58
  ID id_metadata = rb_id_metadata();
37
59
 
38
- #define DECLARE_ALGO_CLASS(bitlen) \
39
- VALUE cDigest_SHA##bitlen;
40
-
41
- FOREACH_BITLEN(DECLARE_ALGO_CLASS)
42
-
60
+ #if 0
61
+ mDigest = rb_define_module("Digest"); /* let rdoc know */
62
+ #endif
43
63
  mDigest = rb_digest_namespace();
44
- cDigest_Base = rb_path2class("Digest::Base");
64
+ cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
65
+
66
+ cDigest_SHA2 = rb_define_class_under(mDigest, "SHA256", cDigest_Base);
67
+ rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha256));
45
68
 
46
- #define DEFINE_ALGO_CLASS(bitlen) \
47
- cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
48
- \
49
- rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
50
- rb_digest_make_metadata(&sha##bitlen));
69
+ cDigest_SHA2 = rb_define_class_under(mDigest, "SHA384", cDigest_Base);
70
+ rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha384));
51
71
 
52
- 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));
53
74
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Digest
4
- VERSION = "3.1.1"
4
+ VERSION = "3.2.0.pre0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digest
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0.pre0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2024-12-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides a framework for message digest libraries.
14
14
  email:
@@ -53,7 +53,6 @@ files:
53
53
  - ext/digest/sha2/sha2.h
54
54
  - ext/digest/sha2/sha2cc.h
55
55
  - ext/digest/sha2/sha2init.c
56
- - ext/digest/test.sh
57
56
  - lib/digest.rb
58
57
  - lib/digest/sha2.rb
59
58
  - lib/digest/version.rb
@@ -78,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
77
  - !ruby/object:Gem::Version
79
78
  version: '0'
80
79
  requirements: []
81
- rubygems_version: 3.4.0.dev
80
+ rubygems_version: 3.5.11
82
81
  signing_key:
83
82
  specification_version: 4
84
83
  summary: Provides a framework for message digest libraries.
data/ext/digest/test.sh DELETED
@@ -1,30 +0,0 @@
1
- #!/bin/sh
2
- #
3
- # $RoughId: test.sh,v 1.5 2001/07/13 15:38:27 knu Exp $
4
- # $Id$
5
-
6
- RUBY=${RUBY:=ruby}
7
- MAKE=${MAKE:=make}
8
- CFLAGS=${CFLAGS:=-Wall}
9
-
10
- ${RUBY} extconf.rb --with-cflags="${CFLAGS}"
11
- ${MAKE} clean
12
- ${MAKE}
13
-
14
- for algo in md5 rmd160 sha1 sha2; do
15
- args=--with-cflags="${CFLAGS}"
16
-
17
- if [ $WITH_BUNDLED_ENGINES ]; then
18
- args="$args --with-bundled-$algo"
19
- fi
20
-
21
- (cd $algo &&
22
- ${RUBY} extconf.rb $args;
23
- ${MAKE} clean;
24
- ${MAKE})
25
- ln -sf ../../$algo/$algo.so lib/digest/
26
- done
27
-
28
- ${RUBY} -I. -I./lib ../../test/digest/test_digest.rb
29
-
30
- rm lib/digest/*.so