From 693c5c3eca0f268c187e58fd789a2a663816ae0b Mon Sep 17 00:00:00 2001 From: Mus M Date: Wed, 26 Jul 2017 13:15:07 -0400 Subject: [PATCH] update parameterized syntax --- src/base_functions.jl | 2 +- src/common.jl | 4 ++-- src/sha2.jl | 2 +- src/sha3.jl | 4 ++-- src/types.jl | 14 +++++++------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/base_functions.jl b/src/base_functions.jl index 99aa6f9585e8b..afa4482988989 100644 --- a/src/base_functions.jl +++ b/src/base_functions.jl @@ -37,4 +37,4 @@ sigma0_512(x) = (S64( 1, UInt64(x)) ⊻ S64( 8, UInt64(x)) ⊻ R( 7, UInt64( sigma1_512(x) = (S64(19, UInt64(x)) ⊻ S64(61, UInt64(x)) ⊻ R( 6, UInt64(x))) # Let's be able to bswap arrays of these types as well -bswap!{T<:Integer}(x::Vector{T}) = map!(bswap, x, x) +bswap!(x::Vector{<:Integer}) = map!(bswap, x, x) diff --git a/src/common.jl b/src/common.jl index d44b483836758..4b089eb477b95 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!(context::T, data::Array{UInt8,1}) where {T<:Union{SHA1_CTX,SHA2_CTX,SHA3_CTX}} # 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!(context::T) where {T<:Union{SHA1_CTX,SHA2_CTX}} 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 259b93757f709..68704a60e0ff7 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!(context::T) where {T<:Union{SHA2_224_CTX,SHA2_256_CTX}} pbuf = Ptr{eltype(context.state)}(pointer(context.buffer)) # Initialize registers with the previous intermediate values (our state) a = context.state[1] diff --git a/src/sha3.jl b/src/sha3.jl index d7e939ea487b1..9707439d458c0 100644 --- a/src/sha3.jl +++ b/src/sha3.jl @@ -1,4 +1,4 @@ -function transform!{T<:SHA3_CTX}(context::T) +function transform!(context::T) where {T<:SHA3_CTX} # First, update state with buffer pbuf = Ptr{eltype(context.state)}(pointer(context.buffer)) for idx in 1:div(blocklen(T),8) @@ -49,7 +49,7 @@ end # Finalize data in the buffer, append total bitlength, and return our precious hash! -function digest!{T<:SHA3_CTX}(context::T) +function digest!(context::T) where {T<:SHA3_CTX} usedspace = context.bytecount % blocklen(T) # If we have anything in the buffer still, pad and transform that data if usedspace < blocklen(T) - 1 diff --git a/src/types.jl b/src/types.jl index d0f5eec687232..7c2d4c0dbb159 100644 --- a/src/types.jl +++ b/src/types.jl @@ -1,8 +1,8 @@ # Type hierarchy to aid in splitting up of SHA2 algorithms # as SHA224/256 are similar, and SHA-384/512 are similar -@compat abstract type SHA_CTX end -@compat abstract type SHA2_CTX <: SHA_CTX end -@compat abstract type SHA3_CTX <: SHA_CTX end +abstract type SHA_CTX end +abstract type SHA2_CTX <: SHA_CTX end +abstract type SHA3_CTX <: SHA_CTX end import Base: copy # We derive SHA1_CTX straight from SHA_CTX since it doesn't have a @@ -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(::Type{T}) where {T<:Union{SHA1_CTX,SHA2_CTX}} = 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))) @@ -126,9 +126,9 @@ SHA1_CTX() = SHA1_CTX(copy(SHA1_initial_hash_value), 0, zeros(UInt8, blocklen(SH # Copy functions -copy{T <: SHA1_CTX}(ctx::T) = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), copy(ctx.W)) -copy{T <: SHA2_CTX}(ctx::T) = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer)) -copy{T <: SHA3_CTX}(ctx::T) = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer)) +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)) # Make printing these types a little friendlier