Skip to content

Commit

Permalink
changed AsRef to AsMut #2
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulLaux committed Dec 26, 2022
1 parent 0f6e301 commit 82cd194
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/note_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,12 @@ pub enum NotePlaintextBytes {
V3([u8; NOTE_PLAINTEXT_SIZE_V3]),
}

impl AsRef<[u8]> for NotePlaintextBytes {
fn as_ref(&self) -> &[u8] {
let ptr: &[u8] = match self {
NotePlaintextBytes::V2(ref x) => x,
NotePlaintextBytes::V3(ref x) => x,
};
ptr
impl AsMut<[u8]> for NotePlaintextBytes {
fn as_mut(&mut self) -> &mut [u8] {
match self {
NotePlaintextBytes::V2(x) => x.as_mut(),
NotePlaintextBytes::V3(x) => x.as_mut(),
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions zcash_note_encryption/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub trait Domain {
type ExtractedCommitmentBytes: Eq + for<'a> From<&'a Self::ExtractedCommitment>;
type Memo;

type NotePlaintextBytes: AsRef<[u8]> + for<'a> From<&'a [u8]>;
type NotePlaintextBytes: AsMut<[u8]> + for<'a> From<&'a [u8]>;
type NoteCiphertextBytes: AsRef<[u8]> + for<'a> From<&'a [u8]>;
type CompactNotePlaintextBytes: AsMut<[u8]> + for<'a> From<&'a [u8]>;
type CompactNoteCiphertextBytes: AsRef<[u8]>;
Expand Down Expand Up @@ -459,14 +459,14 @@ impl<D: Domain> NoteEncryption<D> {
let pk_d = D::get_pk_d(&self.note);
let shared_secret = D::ka_agree_enc(&self.esk, &pk_d);
let key = D::kdf(shared_secret, &D::epk_bytes(&self.epk));
let input = D::note_plaintext_bytes(&self.note, &self.to, &self.memo);
let mut input = D::note_plaintext_bytes(&self.note, &self.to, &self.memo);

let mut output = input.as_ref().to_owned();
let output = input.as_mut();

let tag = ChaCha20Poly1305::new(key.as_ref().into())
.encrypt_in_place_detached([0u8; 12][..].into(), &[], output.as_mut())
.unwrap();
D::NoteCiphertextBytes::from([output, tag.to_vec()].concat().as_ref())
D::NoteCiphertextBytes::from(&[output.as_ref(), tag.as_ref()].concat())
}

/// Generates `outCiphertext` for this note.
Expand Down

0 comments on commit 82cd194

Please sign in to comment.