Add blake2b_hash to targets

This commit is contained in:
Didactic Drunk 2021-04-25 18:14:11 -07:00
parent 690095ae9f
commit 3124048a43
3 changed files with 52 additions and 1 deletions

49
examples/blake2b_hash.cr Normal file
View File

@ -0,0 +1,49 @@
require "option_parser"
require "../src/sodium/digest/blake2b"
require "openssl"
out_size = 64
buf_size = 8192
digest_name = "blake2b"
optp = OptionParser.new
optp.on("--out-size=INT", "") { |arg| out_size = arg.to_i }
optp.on("--buf-size=INT", "") { |arg| buf_size = arg.to_i }
optp.on("--digest=NAME", "") { |arg| digest_name = arg }
optp.parse
class Digest::Null < Digest
def update_impl(data : Bytes) : Nil
end
def final_impl(data : Bytes) : Nil
end
def reset_impl : Nil
end
def digest_size : Int32
0
end
end
digest = case digest_name
when "blake2b"
Sodium::Digest::Blake2b.new out_size
when "null"
Digest::Null.new
else
# raise "foo"
OpenSSL::Digest.new digest_name
end
buf = Bytes.new buf_size
loop do
r = STDIN.read buf
break if r <= 0
digest.update buf[0, r]
end
puts digest.final.hexstring

View File

@ -6,6 +6,8 @@ authors:
- Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com>
crystal: ">= 0.36.0"
targets:
blake2b_hash:
main: examples/blake2b_hash.cr
pwhash_selector:
main: examples/pwhash_selector.cr
libraries:

View File

@ -1,3 +1,3 @@
module Sodium
VERSION = "1.2.1"
VERSION = "1.2.3"
end