Rename sapling::note::OutCiphertext to WrappedNoteKey

This commit is contained in:
Deirdre Connolly 2020-08-28 00:32:01 -04:00 committed by Deirdre Connolly
parent cfc60936ce
commit 5258e891dc
5 changed files with 23 additions and 21 deletions

View File

@ -19,7 +19,7 @@ use super::{
keys::{Diversifier, TransmissionKey}, keys::{Diversifier, TransmissionKey},
}; };
pub use ciphertexts::{EncryptedCiphertext, OutCiphertext}; pub use ciphertexts::{EncryptedNote, WrappedNoteKey};
pub use nullifiers::Nullifier; pub use nullifiers::Nullifier;

View File

@ -2,7 +2,7 @@ use proptest::{arbitrary::any, collection::vec, prelude::*};
use super::*; use super::*;
impl Arbitrary for EncryptedCiphertext { impl Arbitrary for EncryptedNote {
type Parameters = (); type Parameters = ();
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
@ -18,7 +18,7 @@ impl Arbitrary for EncryptedCiphertext {
type Strategy = BoxedStrategy<Self>; type Strategy = BoxedStrategy<Self>;
} }
impl Arbitrary for OutCiphertext { impl Arbitrary for WrappedNoteKey {
type Parameters = (); type Parameters = ();
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {

View File

@ -55,12 +55,14 @@ impl ZcashDeserialize for EncryptedNote {
} }
/// A ciphertext component for encrypted output notes. /// A ciphertext component for encrypted output notes.
///
/// Corresponds to Sapling's 'outCiphertext'
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
pub struct OutCiphertext(#[serde(with = "serde_helpers::BigArray")] pub [u8; 80]); pub struct WrappedNoteKey(#[serde(with = "serde_helpers::BigArray")] pub [u8; 80]);
impl fmt::Debug for OutCiphertext { impl fmt::Debug for WrappedNoteKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("OutCiphertext") f.debug_tuple("WrappedNoteKey")
.field(&hex::encode(&self.0[..])) .field(&hex::encode(&self.0[..]))
.finish() .finish()
} }
@ -68,9 +70,9 @@ impl fmt::Debug for OutCiphertext {
// These impls all only exist because of array length restrictions. // These impls all only exist because of array length restrictions.
impl Copy for OutCiphertext {} impl Copy for WrappedNoteKey {}
impl Clone for OutCiphertext { impl Clone for WrappedNoteKey {
fn clone(&self) -> Self { fn clone(&self) -> Self {
let mut bytes = [0; 80]; let mut bytes = [0; 80];
bytes[..].copy_from_slice(&self.0[..]); bytes[..].copy_from_slice(&self.0[..]);
@ -78,22 +80,22 @@ impl Clone for OutCiphertext {
} }
} }
impl PartialEq for OutCiphertext { impl PartialEq for WrappedNoteKey {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..] self.0[..] == other.0[..]
} }
} }
impl Eq for OutCiphertext {} impl Eq for WrappedNoteKey {}
impl ZcashSerialize for OutCiphertext { impl ZcashSerialize for WrappedNoteKey {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> { fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
writer.write_all(&self.0[..])?; writer.write_all(&self.0[..])?;
Ok(()) Ok(())
} }
} }
impl ZcashDeserialize for OutCiphertext { impl ZcashDeserialize for WrappedNoteKey {
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> { fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
let mut bytes = [0; 80]; let mut bytes = [0; 80];
reader.read_exact(&mut bytes[..])?; reader.read_exact(&mut bytes[..])?;
@ -117,13 +119,13 @@ proptest! {
} }
#[test] #[test]
fn out_ciphertext_roundtrip(oc in any::<OutCiphertext>()) { fn out_ciphertext_roundtrip(oc in any::<WrappedNoteKey>()) {
let mut data = Vec::new(); let mut data = Vec::new();
oc.zcash_serialize(&mut data).expect("OutCiphertext should serialize"); oc.zcash_serialize(&mut data).expect("WrappedNoteKey should serialize");
let oc2 = OutCiphertext::zcash_deserialize(&data[..]).expect("randomized OutCiphertext should deserialize"); let oc2 = WrappedNoteKey::zcash_deserialize(&data[..]).expect("randomized WrappedNoteKey should deserialize");
prop_assert_eq![oc, oc2]; prop_assert_eq![oc, oc2];
} }

View File

@ -20,9 +20,9 @@ pub struct Output {
/// An encoding of an ephemeral Jubjub public key. /// An encoding of an ephemeral Jubjub public key.
pub ephemeral_key: keys::EphemeralPublicKey, pub ephemeral_key: keys::EphemeralPublicKey,
/// A ciphertext component for the encrypted output note. /// A ciphertext component for the encrypted output note.
pub enc_ciphertext: note::EncryptedCiphertext, pub enc_ciphertext: note::EncryptedNote,
/// A ciphertext component for the encrypted output note. /// A ciphertext component for the encrypted output note.
pub out_ciphertext: note::OutCiphertext, pub out_ciphertext: note::WrappedNoteKey,
/// The ZK output proof. /// The ZK output proof.
pub zkproof: Groth16Proof, pub zkproof: Groth16Proof,
} }
@ -45,8 +45,8 @@ impl ZcashDeserialize for Output {
cv: commitment::ValueCommitment::zcash_deserialize(&mut reader)?, cv: commitment::ValueCommitment::zcash_deserialize(&mut reader)?,
cm_u: jubjub::Fq::zcash_deserialize(&mut reader)?, cm_u: jubjub::Fq::zcash_deserialize(&mut reader)?,
ephemeral_key: keys::EphemeralPublicKey::zcash_deserialize(&mut reader)?, ephemeral_key: keys::EphemeralPublicKey::zcash_deserialize(&mut reader)?,
enc_ciphertext: note::EncryptedCiphertext::zcash_deserialize(&mut reader)?, enc_ciphertext: note::EncryptedNote::zcash_deserialize(&mut reader)?,
out_ciphertext: note::OutCiphertext::zcash_deserialize(&mut reader)?, out_ciphertext: note::WrappedNoteKey::zcash_deserialize(&mut reader)?,
zkproof: Groth16Proof::zcash_deserialize(&mut reader)?, zkproof: Groth16Proof::zcash_deserialize(&mut reader)?,
}) })
} }

View File

@ -44,8 +44,8 @@ impl Arbitrary for Output {
any::<commitment::ValueCommitment>(), any::<commitment::ValueCommitment>(),
any::<commitment::NoteCommitment>(), any::<commitment::NoteCommitment>(),
any::<keys::EphemeralPublicKey>(), any::<keys::EphemeralPublicKey>(),
any::<note::EncryptedCiphertext>(), any::<note::EncryptedNote>(),
any::<note::OutCiphertext>(), any::<note::WrappedNoteKey>(),
any::<Groth16Proof>(), any::<Groth16Proof>(),
) )
.prop_map( .prop_map(