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 implements a
Payload
type suggested by @newpavlov here:#40 (comment)
It uses an
impl From<Payload<'msg, 'aad>>
for all plaintexts and ciphertexts, with the idea that users of the API who are unconcerned with AAD can just pass the plaintext/ciphertext message they intend to encrypt or decrypt.With a
plaintext: &[u8]
:Or if you do want to pass AAD:
This makes
msg
andaad
explicit when used so users don't accidentally pass their intended plaintexts asaad
and accidentally expose them because AAD is unencrypted.The
Into<Payload<'_ '_>>
impl on&[u8]
automatically usesb""
(i.e. empty byte slice) as the AAD when it's coerced, which is what I think 99% of users will want.As someone who's concerned about AAD for protocols like Noise (and also other use cases like binding digital signatur keys to ciphertexts), I think for the overwheliming majority of users it's a confusing, superfluous detail. I think this approach neatly leverages Rust's polymorphism to hide this detail in cases where it doesn't matter.