From 22e3e2b46a1ffe6741e73739208e38118b404906 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Tue, 28 Aug 2018 13:08:23 +0800 Subject: [PATCH 1/2] julia 0.7 --- .travis.yml | 3 ++- REQUIRE | 3 +-- appveyor.yml | 52 ++++++++++++++++++++----------------------- src/MD5.jl | 7 +++--- test/nettle.jl | 57 +++++++++++++++++++++++++++--------------------- test/runtests.jl | 14 ++++++------ 6 files changed, 69 insertions(+), 67 deletions(-) diff --git a/.travis.yml b/.travis.yml index 462fc04..592f82c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ os: - linux - osx julia: - - 0.6 + - 0.7 + - 1.0 - nightly notifications: email: false diff --git a/REQUIRE b/REQUIRE index 7cd87bc..859ad46 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1 @@ -julia 0.6 -SHA 0.5.3 +julia 0.7 diff --git a/appveyor.yml b/appveyor.yml index 7eb6a73..c2588f1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,16 +1,18 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -#matrix: -# allow_failures: -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" + - julia_version: 0.7 + - julia_version: 1 + - julia_version: nightly + +platform: + - x86 # 32-bit + - x64 # 64-bit + +# # Uncomment the following lines to allow failures on nightly julia +# # (tests will run but not make your overall status red) +# matrix: +# allow_failures: +# - julia_version: nightly branches: only: @@ -24,24 +26,18 @@ notifications: on_build_status_changed: false install: - - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" -# If there's a newer build queued for the same PR, cancel this one - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $env:JULIA_URL, - "C:\projects\julia-binary.exe") -# Run installer silently, output to C:\projects\julia - - C:\projects\julia-binary.exe /S /D=C:\projects\julia + - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) build_script: -# Need to convert from shallow to complete for Pkg.clone to work - - IF EXIST .git\shallow (git fetch --unshallow) - - C:\projects\julia\bin\julia -e "versioninfo(); - Pkg.clone(pwd(), \"MD5\"); Pkg.build(\"MD5\")" + - echo "%JL_BUILD_SCRIPT%" + - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" test_script: - - C:\projects\julia\bin\julia -e "Pkg.test(\"MD5\")" + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" + +# # Uncomment to support code coverage upload. Should only be enabled for packages +# # which would have coverage gaps without running on Windows +# on_success: +# - echo "%JL_CODECOV_SCRIPT%" +# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" diff --git a/src/MD5.jl b/src/MD5.jl index c7a2ebf..ae5d35d 100644 --- a/src/MD5.jl +++ b/src/MD5.jl @@ -1,6 +1,5 @@ module MD5 -# package code goes here using SHA using SHA: lrot, SHA_CTX @@ -14,7 +13,7 @@ include("core.jl") # Our basic function is to process arrays of bytes -function md5(data::T) where T<:Union{Array{UInt8,1},NTuple{N,UInt8} where N} +function md5(data::T) where T<:Union{AbstractVector{UInt8}, NTuple{N,UInt8} where N} ctx = MD5_CTX() update!(ctx, data) return digest!(ctx) @@ -22,7 +21,7 @@ end # AbstractStrings are a pretty handy thing to be able to crunch through -md5(str::AbstractString) = md5(Vector{UInt8}(str)) +md5(str::AbstractString) = md5(codeunits(str)) # Convenience function for IO devices, allows for things like: # open("test.txt") do f @@ -30,7 +29,7 @@ md5(str::AbstractString) = md5(Vector{UInt8}(str)) # done function md5(io::IO, chunk_size=4*1024) ctx = MD5_CTX() - buff = Vector{UInt8}(chunk_size) + buff = Vector{UInt8}(undef, chunk_size) while !eof(io) num_read = readbytes!(io, buff) update!(ctx, buff[1:num_read]) diff --git a/test/nettle.jl b/test/nettle.jl index d29f6d0..708e25b 100644 --- a/test/nettle.jl +++ b/test/nettle.jl @@ -1,35 +1,42 @@ -import Nettle # redundant imports, so this file can be run standalone -using Base.Test +using Test import MD5 +using Random + +try + 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) + 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 - @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)) + @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 end +catch err + @warn "Cross checking again Nettle could not run, due to error" exception=err end diff --git a/test/runtests.jl b/test/runtests.jl index 5bc4c77..a50aff5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using MD5 -using Base.Test +using Test @testset "String Tests" begin # From the reference https://tools.ietf.org/html/rfc1321 (final page) @@ -14,18 +14,18 @@ using Base.Test end @testset "Different forms of input data consistent" begin - for len in [0,1,10,100,1000] - bytearray = rand(UInt8, len) - str = String(bytearray) - stream = IOBuffer(bytearray) - @test md5(bytearray) == md5(str) + for len in [0,1,10, 100,1000] + bytes = rand(UInt8, len) + str = String(copy(bytes)) # String will take ownership and empty it's array inputs + stream = IOBuffer(bytes) + @test md5(bytes) == md5(str) @test md5(stream) == md5(str) end end @testset "misc" begin @test MD5.digestlen(MD5.MD5_CTX) == length(md5("")) - @test contains(sprint(show, MD5.MD5_CTX()), "MD5") + @test occursin("MD5", sprint(show, MD5.MD5_CTX())) end include("nettle.jl") From 730c8239a0a472c6f7e53ab8fb53f8ff425a9222 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Mon, 24 Sep 2018 14:38:32 +0800 Subject: [PATCH 2/2] reenable nettle tests --- test/nettle.jl | 54 ++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/test/nettle.jl b/test/nettle.jl index 708e25b..b6d8168 100644 --- a/test/nettle.jl +++ b/test/nettle.jl @@ -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 +