Skip to content

Commit

Permalink
More 0.7 compat (#52)
Browse files Browse the repository at this point in the history
* `copy!()` -> `copyto!()`

* Quash more 0.7 compatibility bugs

* Require at least Compat 0.38
  • Loading branch information
staticfloat authored Jan 23, 2018
1 parent de59699 commit af7239e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.6
Compat
Compat 0.38
4 changes: 2 additions & 2 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function update!(context::T, data::U) where {T<:SHA_CTX,
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
copy!(context.buffer, usedspace + 1, data, data_idx + 1, blocklen(T) - usedspace)
copyto!(context.buffer, usedspace + 1, data, data_idx + 1, blocklen(T) - usedspace)

transform!(context)
context.bytecount += blocklen(T) - usedspace
Expand All @@ -23,7 +23,7 @@ function update!(context::T, data::U) where {T<:SHA_CTX,

# There is less than a complete block left, but we need to save the leftovers into context.buffer:
if len > data_idx
copy!(context.buffer, usedspace + 1, data, data_idx + 1, len - data_idx)
copyto!(context.buffer, usedspace + 1, data, data_idx + 1, len - data_idx)
context.bytecount += len - data_idx
end
end
Expand Down
10 changes: 5 additions & 5 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ SHA2_256_CTX() = SHA2_256_CTX(copy(SHA2_256_initial_hash_value), 0, zeros(UInt8,
SHA2_384_CTX() = SHA2_384_CTX(copy(SHA2_384_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_384_CTX)))
SHA2_512_CTX() = SHA2_512_CTX(copy(SHA2_512_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_512_CTX)))

SHA3_224_CTX() = SHA3_224_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_224_CTX)), Vector{UInt64}(5))
SHA3_256_CTX() = SHA3_256_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_256_CTX)), Vector{UInt64}(5))
SHA3_384_CTX() = SHA3_384_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_384_CTX)), Vector{UInt64}(5))
SHA3_512_CTX() = SHA3_512_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_512_CTX)), Vector{UInt64}(5))
SHA3_224_CTX() = SHA3_224_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_224_CTX)), Vector{UInt64}(uninitialized, 5))
SHA3_256_CTX() = SHA3_256_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_256_CTX)), Vector{UInt64}(uninitialized, 5))
SHA3_384_CTX() = SHA3_384_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_384_CTX)), Vector{UInt64}(uninitialized, 5))
SHA3_512_CTX() = SHA3_512_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_512_CTX)), Vector{UInt64}(uninitialized, 5))

# Nickname'd outer constructor methods for SHA2
const SHA224_CTX = SHA2_224_CTX
Expand All @@ -133,7 +133,7 @@ SHA1_CTX() = SHA1_CTX(copy(SHA1_initial_hash_value), 0, zeros(UInt8, blocklen(SH
# Copy functions
copy(ctx::T) where {T<:SHA1_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), copy(ctx.W))
copy(ctx::T) where {T<:SHA2_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer))
copy(ctx::T) where {T<:SHA3_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), Array{UInt64}(5))
copy(ctx::T) where {T<:SHA3_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), Vector{UInt64}(uninitialized, 5))


# Make printing these types a little friendlier
Expand Down
16 changes: 8 additions & 8 deletions test/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ function do_tests(filepath)
# test performance
print("read: ")
@time begin
const fh = open(filepath, "r")
const bytes = read(fh)
fh = open(filepath, "r")
bytes = read(fh)
end
gc()
GC.gc()

print("SHA-1: ")
sha1(bytes)
gc()
GC.gc()
@time sha1(bytes)

print("SHA2-256: ")
sha256(bytes)
gc()
GC.gc()
@time sha256(bytes)

print("SHA2-512: ")
sha512(bytes)
gc()
GC.gc()
@time sha512(bytes)

print("SHA3-256: ")
sha3_256(bytes)
gc()
GC.gc()
@time sha3_256(bytes)

print("SHA3-512: ")
sha3_512(bytes)
gc()
GC.gc()
@time sha3_512(bytes)
end

Expand Down

0 comments on commit af7239e

Please sign in to comment.