Permalink
Browse files

Force ascii encoding on hexdigest output

  • Loading branch information...
1 parent 4774379 commit 2901fd374ab4f0e059824cac9c4c66384ef901a6 @FooBarWidget FooBarWidget committed Oct 6, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 lib/digest/sha3/helpers.rb
View
@@ -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

0 comments on commit 2901fd3

Please sign in to comment.