Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
raphasampaio committed Dec 28, 2024
1 parent 34c32ac commit 89438b1
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/padding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ 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))

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

2 comments on commit 89438b1

@raphasampaio
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/122103

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 89438b1972e89885dbd9051c50404ee16e31ed74
git push origin v0.1.0

Please sign in to comment.