Documentation
¶
Overview ¶
Package atrest protects small local files, such as token caches, with the operating system's own data-protection facility, so their contents are useless once copied off the account that wrote them: into a backup, a synced home directory, or a disk image.
Seal wraps data in a JSON envelope naming the algorithm that protected it. Open reverses Seal and also accepts plaintext, reporting which it was given, so a caller that finds plaintext written by an older build can read it and seal it again instead of discarding it. Where no facility exists, Seal returns data unchanged and Available reports false.
The envelope is JSON so that an older build of a program which hands the file to a JSON parser sees an object it does not recognise, rather than bytes it cannot parse. MSAL's token cache, for one, reads an unrecognised object as an empty cache and prompts for sign-in, where unparseable bytes fail every call.
Protection is against the file leaving its context. Any process running as the same user can open what Seal produced, on every platform.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCannotOpen = errors.New("atrest: sealed data cannot be opened here")
ErrCannotOpen reports sealed data that this build cannot open: sealed on another machine or by another user, sealed by an algorithm this platform lacks, or written by a newer envelope version. The data is not corrupt, but nothing here will read it; a cache in this state should be treated as empty.
Functions ¶
func Available ¶
func Available() bool
Available reports whether Seal protects data on this platform. When false, Seal returns its input unchanged.
func Open ¶
Open returns the plaintext of data and whether data was sealed. Data that is not an envelope is returned as plaintext with sealed false; a caller that can seal should then store it sealed.
A JSON object carrying envelope fields alongside others is also plaintext: an older build that preserves unknown fields read the envelope as an empty document and saved its own contents back around the envelope's fields. Those fields are removed before the plaintext is returned.
An envelope that cannot be opened here returns an error wrapping ErrCannotOpen.
Types ¶
This section is empty.