Skip to content

Commit 09dcdaa

Browse files
committed
Implement Base.copy() for AbstractChaChaStream
1 parent 1734b2b commit 09dcdaa

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/core.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ function getstate(stream::AbstractChaChaStream)
8686
:doublerounds => doublerounds(stream),
8787
)
8888
end
89+
90+
Base.copy(stream::T) where {T <: AbstractChaChaStream} = T(getstate(stream))

test/test_keystream.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ using Test
8686
rand_orig = rand(stream, 1:10, 1024)
8787
rand_repro = rand(stream_repro, 1:10, 1024)
8888
@test rand_orig == rand_repro
89+
90+
# It should also be possible to directly call
91+
# copy() to copy the state of a keystream
92+
stream = ChaCha20Stream()
93+
stream_copy = copy(stream)
94+
95+
@test rand(stream, UInt32, 50) == rand(stream_copy, UInt32, 50)
96+
@test randn(stream, 1500) == randn(stream_copy, 1500)
8997
end
9098

9199
@testset "Encrypt data with a keystream" begin

0 commit comments

Comments
 (0)