If you want to access the underlying value, you can do it by using the wrappedValue property
auth.token.wrappedValue // This will expose the underlying `String`
Codable support
Support for Encodable is provided by the package out of the box.
To have Decodable support you have to provide additional information on how to redact the value. You can easily add support for your type by confirming to the RedactableForDecodable protocol.
For example to automatically support Decodable for your Secret<String> you can add:
extension String: RedactableForDecodable {
public static var redactor: Redactor<Self> { .default }
}
Note that this does not guarantee that the secret is not exposed (for example by encoding it to the disk in plain text) but you can always create a custom type with a dedicated Codable conformance.
License
This library is released under the MIT license. See LICENSE for details.
Secrecy
swift-secrecy
is a simple type wrapper to help you avoid accidentally exposing secrets. This package is heavily inspired by thesecrecy
Rust crateUsage
If one of your types is holding some kind of sensible information it can be easy to accidentally expose that value
For example if you are using a type to hold authentication information
maybe you later are printing debug information to identify problems
Now in your log the password will be printed in cleartext
Instead by using
Secret
you can avoid this mistakes. By changing the type definition intoThe same type of code
Will result in this log
Protecting you from accidental mistakes.
If you want to access the underlying value, you can do it by using the
wrappedValue
propertyCodable support
Support for
Encodable
is provided by the package out of the box. To haveDecodable
support you have to provide additional information on how to redact the value. You can easily add support for your type by confirming to theRedactableForDecodable
protocol. For example to automatically supportDecodable
for yourSecret<String>
you can add:Note that this does not guarantee that the secret is not exposed (for example by encoding it to the disk in plain text) but you can always create a custom type with a dedicated
Codable
conformance.License
This library is released under the MIT license. See LICENSE for details.