Skip to content

Commit

Permalink
reenable nettle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox authored Sep 24, 2018
1 parent 22e3e2b commit 730c823
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions test/nettle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,38 @@ using Test
import MD5
using Random

try
import Nettle

import Nettle

function test_equal_state(md5_value::MD5.MD5_CTX,nettle_value::Nettle.Hasher)
@test nettle_value.state[1:16] ==
reinterpret(UInt8, md5_value.state)
end

@testset "Against Nettle initialize, update!, digest!" begin
for _ in 1:10, chunkcount in [0,1,2,3, 10, 100]
md5_value = MD5.MD5_CTX()
nettle_value = Nettle.Hasher("md5")
test_equal_state(md5_value, nettle_value)
for _ in 1:chunkcount
chunksize = rand(0:10000)
data = rand(UInt8, chunksize)
MD5.update!(md5_value, data)
Nettle.update!(nettle_value, data)
test_equal_state(md5_value,nettle_value)
end
@test MD5.digest!(md5_value) == Nettle.digest!(nettle_value)
function test_equal_state(md5_value::MD5.MD5_CTX,nettle_value::Nettle.Hasher)
@test nettle_value.state[1:16] ==
reinterpret(UInt8, md5_value.state)
end

@testset "Against Nettle initialize, update!, digest!" begin
for _ in 1:10, chunkcount in [0,1,2,3, 10, 100]
md5_value = MD5.MD5_CTX()
nettle_value = Nettle.Hasher("md5")
test_equal_state(md5_value, nettle_value)
for _ in 1:chunkcount
chunksize = rand(0:10000)
data = rand(UInt8, chunksize)
MD5.update!(md5_value, data)
Nettle.update!(nettle_value, data)
test_equal_state(md5_value,nettle_value)
end
@test MD5.digest!(md5_value) == Nettle.digest!(nettle_value)
end
end

@testset "Against Nettle end to end" begin
for offset in [0,10^3, 10^4, 10^5]
iter = offset:(offset+1000)
for l in iter
s = randstring(l)
@test Nettle.hexdigest("md5", s) == bytes2hex(md5(s))
end
@testset "Against Nettle end to end" begin
for offset in [0,10^3, 10^4, 10^5]
iter = offset:(offset+1000)
for l in iter
s = randstring(l)
@test Nettle.hexdigest("md5", s) == bytes2hex(md5(s))
end
end
catch err
@warn "Cross checking again Nettle could not run, due to error" exception=err
end

0 comments on commit 730c823

Please sign in to comment.