Skip to content

Commit e785faa

Browse files
Address review comments from zcash PR zcash#177 (#13)
- Add type aliases for `EncCiphertext` and `CompactEncCiphertext` - Implement `enc_ciphertext_compact` for `OutputDescription`
1 parent 42e3a0c commit e785faa

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/bundle.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use crate::{
1313
constants::GROTH_PROOF_SIZE,
1414
note::ExtractedNoteCommitment,
1515
note_encryption::{
16-
CompactOutputDescription, SaplingDomain, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE,
16+
CompactEncCiphertext, CompactOutputDescription, EncCiphertext, SaplingDomain,
17+
COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE,
1718
},
1819
value::ValueCommitment,
1920
Nullifier,
@@ -433,12 +434,14 @@ impl<A> ShieldedOutput<SaplingDomain> for OutputDescription<A> {
433434
self.cmu.to_bytes()
434435
}
435436

436-
fn enc_ciphertext(&self) -> Option<&NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>> {
437+
fn enc_ciphertext(&self) -> Option<&EncCiphertext> {
437438
Some(&self.enc_ciphertext)
438439
}
439440

440-
fn enc_ciphertext_compact(&self) -> NoteBytesData<{ COMPACT_NOTE_SIZE }> {
441-
unimplemented!("This function is not required for sapling")
441+
fn enc_ciphertext_compact(&self) -> CompactEncCiphertext {
442+
let mut data = [0u8; COMPACT_NOTE_SIZE];
443+
data.copy_from_slice(&self.enc_ciphertext.as_ref()[..COMPACT_NOTE_SIZE]);
444+
NoteBytesData(data)
442445
}
443446
}
444447

@@ -498,12 +501,12 @@ impl OutputDescriptionV5 {
498501

499502
impl<A> From<OutputDescription<A>> for CompactOutputDescription {
500503
fn from(out: OutputDescription<A>) -> CompactOutputDescription {
504+
let enc_ciphertext = out.enc_ciphertext_compact().0;
505+
501506
CompactOutputDescription {
502507
ephemeral_key: out.ephemeral_key,
503508
cmu: out.cmu,
504-
enc_ciphertext: out.enc_ciphertext.as_ref()[..COMPACT_NOTE_SIZE]
505-
.try_into()
506-
.unwrap(),
509+
enc_ciphertext,
507510
}
508511
}
509512
}

src/note_encryption.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ impl SaplingDomain {
140140
}
141141
}
142142

143+
pub(crate) type EncCiphertext = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>;
144+
pub(crate) type CompactEncCiphertext = NoteBytesData<{ COMPACT_NOTE_SIZE }>;
145+
143146
impl Domain for SaplingDomain {
144147
type EphemeralSecretKey = EphemeralSecretKey;
145148
// It is acceptable for this to be a point rather than a byte array, because we
@@ -160,9 +163,9 @@ impl Domain for SaplingDomain {
160163
type Memo = [u8; MEMO_SIZE];
161164

162165
type NotePlaintextBytes = NoteBytesData<{ NOTE_PLAINTEXT_SIZE }>;
163-
type NoteCiphertextBytes = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>;
166+
type NoteCiphertextBytes = EncCiphertext;
164167
type CompactNotePlaintextBytes = NoteBytesData<{ COMPACT_NOTE_SIZE }>;
165-
type CompactNoteCiphertextBytes = NoteBytesData<{ COMPACT_NOTE_SIZE }>;
168+
type CompactNoteCiphertextBytes = CompactEncCiphertext;
166169

167170
fn derive_esk(note: &Self::Note) -> Option<Self::EphemeralSecretKey> {
168171
note.derive_esk()

0 commit comments

Comments
 (0)