Force ascii encoding on hexdigest output

This commit is contained in:
Hongli Lai (Phusion) 2012-10-06 12:02:57 +02:00
parent 4774379efb
commit 2901fd374a

View file

@ -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