From 2901fd374ab4f0e059824cac9c4c66384ef901a6 Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Sat, 6 Oct 2012 12:02:57 +0200 Subject: [PATCH] Force ascii encoding on hexdigest output --- lib/digest/sha3/helpers.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/digest/sha3/helpers.rb b/lib/digest/sha3/helpers.rb index d68c5ab..d9349ac 100644 --- a/lib/digest/sha3/helpers.rb +++ b/lib/digest/sha3/helpers.rb @@ -1,9 +1,20 @@ +# encoding: ascii Digest::SHA3.class_eval do def self.hexdigest(*args) - digest(*args).unpack("H*").first + force_ascii(digest(*args).unpack("H*").first) end def hexdigest - digest.unpack("H*").first + Digest::SHA3.force_ascii(digest.unpack("H*").first) + end + + if ''.respond_to?(:force_encoding) + def self.force_ascii(str) + str.force_encoding('ascii') + end + else + def self.force_ascii(str) + str + end end end