zcash_primitives: Move Sapling `HashSer` impl into `merkle_tree` module
The `HashSer` trait will remain in `zcash_primitives` while the Sapling type it is implemented for moves to `sapling-crypto`. Part of zcash/librustzcash#1044.
This commit is contained in:
parent
8acc03783e
commit
906e203663
|
@ -23,6 +23,23 @@ pub trait HashSer {
|
|||
fn write<W: Write>(&self, writer: W) -> io::Result<()>;
|
||||
}
|
||||
|
||||
impl HashSer for sapling::Node {
|
||||
fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
||||
let mut repr = [0u8; 32];
|
||||
reader.read_exact(&mut repr)?;
|
||||
Option::from(Self::from_bytes(repr)).ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
"Non-canonical encoding of Jubjub base field value.",
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||
writer.write_all(&self.to_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl HashSer for MerkleHashOrchard {
|
||||
fn read<R: Read>(mut reader: R) -> io::Result<Self>
|
||||
where
|
||||
|
|
|
@ -5,13 +5,11 @@ use lazy_static::lazy_static;
|
|||
use subtle::CtOption;
|
||||
|
||||
use std::fmt;
|
||||
use std::io::{self, Read, Write};
|
||||
|
||||
use super::{
|
||||
note::ExtractedNoteCommitment,
|
||||
pedersen_hash::{pedersen_hash, Personalization},
|
||||
};
|
||||
use crate::merkle_tree::HashSer;
|
||||
|
||||
pub const NOTE_COMMITMENT_TREE_DEPTH: u8 = 32;
|
||||
pub type CommitmentTree =
|
||||
|
@ -123,23 +121,6 @@ impl Hashable for Node {
|
|||
}
|
||||
}
|
||||
|
||||
impl HashSer for Node {
|
||||
fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
||||
let mut repr = [0u8; 32];
|
||||
reader.read_exact(&mut repr)?;
|
||||
Option::from(Self::from_bytes(repr)).ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
"Non-canonical encoding of Jubjub base field value.",
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||
writer.write_all(&self.to_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Node> for bls12_381::Scalar {
|
||||
fn from(node: Node) -> Self {
|
||||
node.0
|
||||
|
|
Loading…
Reference in New Issue