I’ve been playing with creating a custom
Password string type which would be securely logged and printed in obfuscated form.
I came up with:
struct Password <: AbstractString contents::String end Base.show(io::IO, p::Password) = print(io, "*******") Base.print(p::Password) = print("******") Base.iterate(p::Password) = iterate(p.contents) Base.iterate(p::Password, i::Int) = iterate(p.contents, i) Base.ncodeunits(p::Password) = ncodeunits(p.contents) Base.isvalid(p::Password, i::Int) = isvalid(p.contents, i) secret_pass = Password("12345") @show secret_pass @info secret_pass print(secret_pass)
Works fine with the exception of
@info. Output here:
secret_pass = ****** [ Info: 12345 ******
What should be overwritten in order to affect logging output?