From 82cd194acc646913c188751810b853f206906f64 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 26 Dec 2022 09:40:41 +0200 Subject: [PATCH] changed AsRef to AsMut #2 --- src/note_encryption.rs | 13 ++++++------- zcash_note_encryption/src/lib.rs | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 872f91146..31d3e1ed5 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -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(), + } } } diff --git a/zcash_note_encryption/src/lib.rs b/zcash_note_encryption/src/lib.rs index e579b8576..2a1ea1dd0 100644 --- a/zcash_note_encryption/src/lib.rs +++ b/zcash_note_encryption/src/lib.rs @@ -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]>; @@ -459,14 +459,14 @@ impl NoteEncryption { 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.