summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-28 14:14:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-28 14:14:21 +0000
commit9f9add3eb5006473dfabac3e994e904b5c1979fe (patch)
treec20c40fec128cdee6a0a38bde0fa59a2b0e13da0
parentd90b767d2bf346c87132e62df9c2159f7c8b97c0 (diff)
PStore: select checksum algorithm
* lib/pstore.rb (PStore::CHECKSUM_ALGO): find available hashing algorithm for checksum. MD5 is not available in FIPS mode. [Feature #6943] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--lib/pstore.rb9
2 files changed, 13 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 44b1c33562..ee86f30a80 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Sep 28 23:14:19 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/pstore.rb (PStore::CHECKSUM_ALGO): find available hashing
+ algorithm for checksum. MD5 is not available in FIPS mode.
+ [Feature #6943]
+
Wed Sep 28 13:00:25 2016 ksss <co000ri@gmail.com>
* signal.c (sig_signame): [DOC] Add documentation in the case of
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 87153ed2cd..6fddb319b7 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -8,7 +8,7 @@
#
# See PStore for documentation.
-require "digest/md5"
+require "digest"
#
# PStore implements a file based persistence mechanism based on a Hash. User
@@ -352,7 +352,12 @@ class PStore
private
# Constant for relieving Ruby's garbage collector.
- CHECKSUM_ALGO = Digest::MD5
+ CHECKSUM_ALGO = %w[SHA512 SHA384 SHA256 SHA1 RMD160 MD5].each do |algo|
+ begin
+ break Digest(algo)
+ rescue LoadError
+ end
+ end
EMPTY_STRING = ""
EMPTY_MARSHAL_DATA = Marshal.dump({})
EMPTY_MARSHAL_CHECKSUM = CHECKSUM_ALGO.digest(EMPTY_MARSHAL_DATA)