Force ascii encoding on hexdigest output
This commit is contained in:
parent
4774379efb
commit
2901fd374a
1 changed files with 13 additions and 2 deletions
|
@ -1,9 +1,20 @@
|
||||||
|
# encoding: ascii
|
||||||
Digest::SHA3.class_eval do
|
Digest::SHA3.class_eval do
|
||||||
def self.hexdigest(*args)
|
def self.hexdigest(*args)
|
||||||
digest(*args).unpack("H*").first
|
force_ascii(digest(*args).unpack("H*").first)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hexdigest
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue