Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy(::AESBlock) #13

Merged
merged 2 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ function Base.setindex!(block::B, val, i) where {B<:AESBlock}
block.data[16*(block.offset - 1) + i] = eltype(block.data)(val)
end

function Base.copy(block::AESBlock)
return AESBlock(copy(block.data), block.offset)
end

function Base.copyto!(block::B, arr::AbstractArray{T2,1}) where {B<:AESBlock, T2}
for i in 1:16
block.data[16*(block.offset - 1) + i] = eltype(block.data)(arr[i])
Expand Down
7 changes: 7 additions & 0 deletions test/interface.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using AES, Test

a=AES.AESBlock(rand(UInt8, 100), 3)
ac=copy(a)
@test ac == a
@test ac !== a
@test ac isa AES.AESBlock
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using SafeTestsets

@time begin
@time @safetestset "Interface Tests" begin include("interface.jl") end
@time @safetestset "Block Encryption/Decryption tests" begin include("blocktest.jl") end
@time @safetestset "CBC Mode tests" begin include("cbc.jl") end
@time @safetestset "CTR Mode tests" begin include("ctr.jl") end
Expand Down