Skip to content

Commit

Permalink
fixed bug in SHA.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausC committed Dec 6, 2020
1 parent 2ced28b commit c649cbe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion stdlib/SHA/src/SHA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ for (f, ctx) in [(:sha1, :SHA1_CTX),
end
function $g(key::Vector{UInt8}, io::IO, chunk_size=4*1024)
ctx = HMAC_CTX($ctx(), key)
buff = Vector{UInt8}(chunk_size)
buff = Vector{UInt8}(undef, chunk_size)
while !eof(io)
num_read = readbytes!(io, buff)
update!(ctx, buff, num_read)
Expand Down
8 changes: 5 additions & 3 deletions stdlib/SHA/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,17 @@ for (key, msg, fun, hash) in (
(b"key", b"The quick brown fox jumps over the lazy dog", hmac_sha256, "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"),
)
global nerrors
digest = bytes2hex(fun(Vector(key), Vector(msg)))
if digest != hash
digest1 = bytes2hex(fun(Vector(key), Vector(msg)))
digest2 = bytes2hex(fun(Vector(key), IOBuffer(Vector(msg))))
if digest1 != hash || digest2 != hash
print("\n")
@warn(
"""
For $fun($(String(key)), $(String(msg))) expected:
$hash
Calculated:
$digest
$digest1
$digest2
""")
nerrors += 1
else
Expand Down

0 comments on commit c649cbe

Please sign in to comment.