From 89438b1972e89885dbd9051c50404ee16e31ed74 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sat, 28 Dec 2024 01:01:40 -0300 Subject: [PATCH] Initial commit --- src/padding.jl | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/padding.jl b/src/padding.jl index b1c7276..b748ecb 100644 --- a/src/padding.jl +++ b/src/padding.jl @@ -3,8 +3,8 @@ add_padding(data::AbstractString, args...) = add_padding(Vector{UInt8}(data), ar add_padding(data::Vector{UInt32}, args...) = add_padding(to_vector_uint8(data), args...) function add_padding(data::Vector{UInt8}, block_size::Integer = 16) - padlen = block_size - (sizeof(data) % block_size) - return [data; map(i -> UInt8(padlen), 1:padlen)] + size = block_size - (length(data) % block_size) + return vcat(data, [UInt8(size) for _ in 1:size]) end remove_padding(data::AbstractString) = remove_padding(Vector{UInt8}(data)) @@ -12,10 +12,5 @@ remove_padding(data::AbstractString) = remove_padding(Vector{UInt8}(data)) remove_padding(data::Vector{UInt32}) = remove_padding(to_vector_uint8(data)) function remove_padding(data::Vector{UInt8}) - padlen = data[end] - if all(data[end-padlen+1:end-1] .== data[end]) - return data[1:end-padlen] - else - throw(ArgumentError("Invalid PKCS5 padding")) - end + return data[1:end-data[end]] end