This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds example usage of using AEAD to encrypt data. I think this specific functionality is especially worth documenting as @vincenthz recommended packages like clientsession use it. Also, it seems preferable to encourage AEAD rather than e.g. raw AES CTR, where a user might not add a MAC in places they should, or could MAC in an insecure way.
The example code is a longer than I'd like, but the extra space spent on e.g. newtypes makes me more comfortable with a random user coming along and copy/pasting this into their codebase.
This being example code, having the most generally applicable code is probably important. If you think there are better choices than AES256/OCB mode in terms of speed/security/legal tradeoffs, that could be changed. I'm slightly unclear on the OCB patents—it seems like it's fine for e.g. a commercial webapp to use it, as long as it's not on behalf of a military?
The example code is hidden in a collapsible section to keep the docs looking clean:
Rendered: