From 383142826a5e6293109c29b1c4f2b356c30153a5 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Mon, 18 Jul 2016 22:43:50 -0700 Subject: [PATCH 1/4] test separately on 0.3 and 0.4 on travis 0.3 still supported according to REQUIRE --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea47c751d8467..9a743200109ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ os: - linux - osx julia: - - release + - 0.3 + - 0.4 - nightly notifications: email: false @@ -12,4 +13,4 @@ script: - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - julia -e 'Pkg.clone(pwd()); Pkg.test("SHA", coverage=true)' after_success: - - julia -e 'cd(Pkg.dir("SHA")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' \ No newline at end of file + - julia -e 'cd(Pkg.dir("SHA")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' From 97c2fa374c69e0f293902e7c7d6579864e29a1d8 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Mon, 18 Jul 2016 22:58:02 -0700 Subject: [PATCH 2/4] Use at-compat for Union and Dict --- src/common.jl | 4 ++-- src/sha2.jl | 4 ++-- src/types.jl | 2 +- test/runtests.jl | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common.jl b/src/common.jl index 83c056a61317e..79fec75d796c2 100644 --- a/src/common.jl +++ b/src/common.jl @@ -2,7 +2,7 @@ # update! takes in variable-length data, buffering it into blocklen()-sized pieces, # calling transform!() when necessary to update the internal hash state. -function update!{T<:Union{SHA1_CTX,SHA2_CTX,SHA3_CTX}}(context::T, data::Array{UInt8,1}) +function update!{T<:@compat(Union{SHA1_CTX,SHA2_CTX,SHA3_CTX})}(context::T, data::Array{UInt8,1}) # We need to do all our arithmetic in the proper bitwidth UIntXXX = typeof(context.bytecount) @@ -33,7 +33,7 @@ end # Clear out any saved data in the buffer, append total bitlength, and return our precious hash! -function digest!{T<:Union{SHA1_CTX,SHA2_CTX}}(context::T) +function digest!{T<:@compat(Union{SHA1_CTX,SHA2_CTX})}(context::T) usedspace = context.bytecount % blocklen(T) # If we have anything in the buffer still, pad and transform that data if usedspace > 0 diff --git a/src/sha2.jl b/src/sha2.jl index 921e0fe15a398..13fa5abb675cf 100644 --- a/src/sha2.jl +++ b/src/sha2.jl @@ -1,4 +1,4 @@ -function transform!{T<:Union{SHA2_224_CTX,SHA2_256_CTX}}(context::T) +function transform!{T<:@compat(Union{SHA2_224_CTX,SHA2_256_CTX})}(context::T) buffer = reinterpret(eltype(context.state), context.buffer) # Initialize registers with the previous intermediate values (our state) a = context.state[1] @@ -65,7 +65,7 @@ function transform!{T<:Union{SHA2_224_CTX,SHA2_256_CTX}}(context::T) end -function transform!(context::Union{SHA2_384_CTX,SHA2_512_CTX}) +function transform!(context::@compat(Union{SHA2_384_CTX,SHA2_512_CTX})) buffer = reinterpret(eltype(context.state), context.buffer) # Initialize registers with the prev. intermediate value a = context.state[1] diff --git a/src/types.jl b/src/types.jl index 0cfc61d487a9c..80931c8149367 100644 --- a/src/types.jl +++ b/src/types.jl @@ -102,7 +102,7 @@ blocklen(::Type{SHA3_512_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_512_CTX)) # short_blocklen is the size of a block minus the width of bytecount -short_blocklen{T<:Union{SHA1_CTX,SHA2_CTX}}(::Type{T}) = blocklen(T) - 2*sizeof(state_type(T)) +short_blocklen{T<:@compat(Union{SHA1_CTX,SHA2_CTX})}(::Type{T}) = blocklen(T) - 2*sizeof(state_type(T)) # Once the "blocklen" methods are defined, we can define our outer constructors for SHA types: SHA2_224_CTX() = SHA2_224_CTX(copy(SHA2_224_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_224_CTX))) diff --git a/test/runtests.jl b/test/runtests.jl index d7086de73dea9..422e86d2aac1b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,7 +8,7 @@ data = Any["", "test", lorem, so_many_as] # Descriptions of the data, the SHA functions we'll run on the data, etc... data_desc = ["the empty string", "the string \"test\"", "lorem ipsum", "one million a's"] -sha_types =Dict(sha1 => SHA.SHA1_CTX, +sha_types = @compat Dict(sha1 => SHA.SHA1_CTX, sha2_224 => SHA.SHA2_224_CTX, sha2_256 => SHA.SHA2_256_CTX, sha2_384 => SHA.SHA2_384_CTX, sha2_512 => SHA.SHA2_512_CTX, sha3_224 => SHA.SHA3_224_CTX, sha3_256 => SHA.SHA3_256_CTX, sha3_384 => SHA.SHA3_384_CTX, sha3_512 => SHA.SHA3_512_CTX) sha_funcs = [sha1, From 5dc0051c15e5a6831e17e8e5969009570b672934 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Mon, 18 Jul 2016 23:02:12 -0700 Subject: [PATCH 3/4] Use at-compat or convert for call overloading --- src/common.jl | 6 +++--- src/types.jl | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/common.jl b/src/common.jl index 79fec75d796c2..0cc58a783e67e 100644 --- a/src/common.jl +++ b/src/common.jl @@ -7,8 +7,8 @@ function update!{T<:@compat(Union{SHA1_CTX,SHA2_CTX,SHA3_CTX})}(context::T, data UIntXXX = typeof(context.bytecount) # Process as many complete blocks as possible - len = UIntXXX(length(data)) - data_idx = UIntXXX(0) + len = convert(UIntXXX, length(data)) + data_idx = convert(UIntXXX, 0) usedspace = context.bytecount % blocklen(T) while len - data_idx + usedspace >= blocklen(T) # Fill up as much of the buffer as we can with the data given us @@ -19,7 +19,7 @@ function update!{T<:@compat(Union{SHA1_CTX,SHA2_CTX,SHA3_CTX})}(context::T, data transform!(context) context.bytecount += blocklen(T) - usedspace data_idx += blocklen(T) - usedspace - usedspace = UIntXXX(0) + usedspace = convert(UIntXXX, 0) end # There is less than a complete block left, but we need to save the leftovers into context.buffer: diff --git a/src/types.jl b/src/types.jl index 80931c8149367..a116885fd3c43 100644 --- a/src/types.jl +++ b/src/types.jl @@ -89,16 +89,16 @@ state_type(::Type{SHA2_384_CTX}) = UInt64 state_type(::Type{SHA2_512_CTX}) = UInt64 # blocklen is the number of bytes of data processed by the transform!() function at once -blocklen(::Type{SHA1_CTX}) = UInt64(64) -blocklen(::Type{SHA2_224_CTX}) = UInt64(64) -blocklen(::Type{SHA2_256_CTX}) = UInt64(64) -blocklen(::Type{SHA2_384_CTX}) = UInt64(128) -blocklen(::Type{SHA2_512_CTX}) = UInt64(128) - -blocklen(::Type{SHA3_224_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_224_CTX)) -blocklen(::Type{SHA3_256_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_256_CTX)) -blocklen(::Type{SHA3_384_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_384_CTX)) -blocklen(::Type{SHA3_512_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_512_CTX)) +blocklen(::Type{SHA1_CTX}) = @compat UInt64(64) +blocklen(::Type{SHA2_224_CTX}) = @compat UInt64(64) +blocklen(::Type{SHA2_256_CTX}) = @compat UInt64(64) +blocklen(::Type{SHA2_384_CTX}) = @compat UInt64(128) +blocklen(::Type{SHA2_512_CTX}) = @compat UInt64(128) + +blocklen(::Type{SHA3_224_CTX}) = @compat UInt64(25*8 - 2*digestlen(SHA3_224_CTX)) +blocklen(::Type{SHA3_256_CTX}) = @compat UInt64(25*8 - 2*digestlen(SHA3_256_CTX)) +blocklen(::Type{SHA3_384_CTX}) = @compat UInt64(25*8 - 2*digestlen(SHA3_384_CTX)) +blocklen(::Type{SHA3_512_CTX}) = @compat UInt64(25*8 - 2*digestlen(SHA3_512_CTX)) # short_blocklen is the size of a block minus the width of bytecount From 80e58afeca41e76819c9f5572a6121d984b40a3b Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Mon, 18 Jul 2016 23:02:37 -0700 Subject: [PATCH 4/4] Use Array(UInt64, 5) instead of Array{UInt64,1}(5) --- src/sha3.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sha3.jl b/src/sha3.jl index 9acf5d84df7d3..acb3557120d61 100644 --- a/src/sha3.jl +++ b/src/sha3.jl @@ -4,7 +4,7 @@ function transform!{T<:SHA3_CTX}(context::T) for idx in 1:div(blocklen(T),8) context.state[idx] $= buffer_as_uint64[idx] end - bc = Array{UInt64,1}(5) + bc = Array(UInt64, 5) # We always assume 24 rounds for round in 0:23