Skip to content

Commit

Permalink
Xref in docs and more tests for SecretBuffer (JuliaLang#29942)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt authored and StefanKarpinski committed Nov 6, 2018
1 parent 0fde275 commit 618ee77
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions base/secretbuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Base.SecretBuffer()
An IOBuffer-like object where the contents will be securely wiped when garbage collected.
An [`IOBuffer`](@ref)-like object where the contents will be securely wiped when garbage collected.
It is considered best practice to wipe the buffer using `Base.shred!(::SecretBuffer)` as
soon as the secure data are no longer required. When initializing with existing data, the
Expand Down Expand Up @@ -48,7 +48,7 @@ A convenience constructor to initialize a `SecretBuffer` from a non-secret strin
Strings are bad at keeping secrets because they are unable to be securely
zeroed or destroyed. Therefore, avoid using this constructor with secret data.
Instead of starting with a string, either construct the `SecretBuffer`
incrementally with `SecretBuffer()` and `write`, or use a `Vector{UInt8}` with
incrementally with `SecretBuffer()` and [`write`](@ref), or use a `Vector{UInt8}` with
the `Base.SecretBuffer!(::Vector{UInt8})` constructor.
"""
SecretBuffer(str::AbstractString) = SecretBuffer(String(str))
Expand Down
14 changes: 13 additions & 1 deletion test/secretbuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ using Test
@test Base.unsafe_string(ptr3) == ""
@test s1 == s2 == s3

shred!(s1); shred!(s2); shred!(s3)
s4 = SecretBuffer(split("setec astronomy", " ")[1]) # initialize from SubString
s5 = convert(SecretBuffer, split("setec astronomy", " ")[1]) # initialize from SubString
@test s4 == s5
shred!(s1); shred!(s2); shred!(s3); shred!(s4), shred!(s5);
end
@testset "basics" begin
s1 = SecretBuffer("setec astronomy")
@test sprint(show, s1) == "SecretBuffer(\"*******\")"
@test !isempty(s1)
shred!(s1)
s2 = SecretBuffer!([0x00])
@test_throws ArgumentError Base.cconvert(Cstring, s2)
shred!(s2)
end
end

0 comments on commit 618ee77

Please sign in to comment.