zebra_chain/primitives/proofs/
bctv14.rs
1use std::{fmt, io};
4
5use serde::{Deserialize, Serialize};
6use serde_big_array::BigArray;
7
8use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};
9
10#[derive(Serialize, Deserialize)]
12pub struct Bctv14Proof(#[serde(with = "BigArray")] pub [u8; 296]);
13
14impl fmt::Debug for Bctv14Proof {
15 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16 f.debug_tuple("Bctv14Proof")
17 .field(&hex::encode(&self.0[..]))
18 .finish()
19 }
20}
21
22impl Copy for Bctv14Proof {}
25
26impl Clone for Bctv14Proof {
27 fn clone(&self) -> Self {
28 *self
29 }
30}
31
32impl PartialEq for Bctv14Proof {
33 fn eq(&self, other: &Self) -> bool {
34 self.0[..] == other.0[..]
35 }
36}
37
38impl Eq for Bctv14Proof {}
39
40impl ZcashSerialize for Bctv14Proof {
41 fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
42 writer.write_all(&self.0[..])?;
43 Ok(())
44 }
45}
46
47impl ZcashDeserialize for Bctv14Proof {
48 fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
49 let mut bytes = [0; 296];
50 reader.read_exact(&mut bytes[..])?;
51 Ok(Self(bytes))
52 }
53}
54
55#[cfg(any(test, feature = "proptest-impl"))]
56use proptest::{collection::vec, prelude::*};
57
58#[cfg(any(test, feature = "proptest-impl"))]
59impl Arbitrary for Bctv14Proof {
60 type Parameters = ();
61
62 fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
63 (vec(any::<u8>(), 296))
64 .prop_map(|v| {
65 let mut bytes = [0; 296];
66 bytes.copy_from_slice(v.as_slice());
67 Self(bytes)
68 })
69 .boxed()
70 }
71
72 type Strategy = BoxedStrategy<Self>;
73}