diff --git a/examples/blake2b_hash.cr b/examples/blake2b_hash.cr new file mode 100644 index 0000000..5ecc047 --- /dev/null +++ b/examples/blake2b_hash.cr @@ -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 diff --git a/shard.yml b/shard.yml index 70f2431..fe51ca9 100644 --- a/shard.yml +++ b/shard.yml @@ -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: diff --git a/src/sodium/version.cr b/src/sodium/version.cr index e8695ad..4f66092 100644 --- a/src/sodium/version.cr +++ b/src/sodium/version.cr @@ -1,3 +1,3 @@ module Sodium - VERSION = "1.2.1" + VERSION = "1.2.3" end