mirror of https://github.com/zcash/halo2.git
clippy: Use Option::ok_or_else to construct errors from functions
This commit is contained in:
parent
6c6b30dde4
commit
6983bd1bbc
|
@ -66,10 +66,9 @@ impl<R: Read, C: CurveAffine> TranscriptRead<C> for DummyHashRead<R, C> {
|
||||||
fn read_point(&mut self) -> io::Result<C> {
|
fn read_point(&mut self) -> io::Result<C> {
|
||||||
let mut compressed = [0u8; 32];
|
let mut compressed = [0u8; 32];
|
||||||
self.reader.read_exact(&mut compressed[..])?;
|
self.reader.read_exact(&mut compressed[..])?;
|
||||||
let point: C = Option::from(C::from_bytes(&compressed)).ok_or(io::Error::new(
|
let point: C = Option::from(C::from_bytes(&compressed)).ok_or_else(|| {
|
||||||
io::ErrorKind::Other,
|
io::Error::new(io::ErrorKind::Other, "invalid point encoding in proof")
|
||||||
"invalid point encoding in proof",
|
})?;
|
||||||
))?;
|
|
||||||
self.common_point(point)?;
|
self.common_point(point)?;
|
||||||
|
|
||||||
Ok(point)
|
Ok(point)
|
||||||
|
@ -78,10 +77,12 @@ impl<R: Read, C: CurveAffine> TranscriptRead<C> for DummyHashRead<R, C> {
|
||||||
fn read_scalar(&mut self) -> io::Result<C::Scalar> {
|
fn read_scalar(&mut self) -> io::Result<C::Scalar> {
|
||||||
let mut data = [0u8; 32];
|
let mut data = [0u8; 32];
|
||||||
self.reader.read_exact(&mut data)?;
|
self.reader.read_exact(&mut data)?;
|
||||||
let scalar = Option::from(C::Scalar::from_bytes(&data)).ok_or(io::Error::new(
|
let scalar = Option::from(C::Scalar::from_bytes(&data)).ok_or_else(|| {
|
||||||
|
io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
"invalid field element encoding in proof",
|
"invalid field element encoding in proof",
|
||||||
))?;
|
)
|
||||||
|
})?;
|
||||||
self.scalar_state += &(scalar * &C::Scalar::ZETA);
|
self.scalar_state += &(scalar * &C::Scalar::ZETA);
|
||||||
self.scalar_state = self.scalar_state.square();
|
self.scalar_state = self.scalar_state.square();
|
||||||
self.read_scalar = true;
|
self.read_scalar = true;
|
||||||
|
@ -92,10 +93,12 @@ impl<R: Read, C: CurveAffine> TranscriptRead<C> for DummyHashRead<R, C> {
|
||||||
|
|
||||||
impl<R: Read, C: CurveAffine> Transcript<C> for DummyHashRead<R, C> {
|
impl<R: Read, C: CurveAffine> Transcript<C> for DummyHashRead<R, C> {
|
||||||
fn common_point(&mut self, point: C) -> io::Result<()> {
|
fn common_point(&mut self, point: C) -> io::Result<()> {
|
||||||
let (x, y) = Option::from(point.get_xy()).ok_or(io::Error::new(
|
let (x, y) = Option::from(point.get_xy()).ok_or_else(|| {
|
||||||
|
io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
"cannot write points at infinity to the transcript",
|
"cannot write points at infinity to the transcript",
|
||||||
))?;
|
)
|
||||||
|
})?;
|
||||||
self.base_state += &(x * &C::Base::ZETA);
|
self.base_state += &(x * &C::Base::ZETA);
|
||||||
self.base_state = self.base_state.square();
|
self.base_state = self.base_state.square();
|
||||||
self.base_state += &(y * &C::Base::ZETA);
|
self.base_state += &(y * &C::Base::ZETA);
|
||||||
|
@ -170,10 +173,12 @@ impl<W: Write, C: CurveAffine> TranscriptWrite<C> for DummyHashWrite<W, C> {
|
||||||
|
|
||||||
impl<W: Write, C: CurveAffine> Transcript<C> for DummyHashWrite<W, C> {
|
impl<W: Write, C: CurveAffine> Transcript<C> for DummyHashWrite<W, C> {
|
||||||
fn common_point(&mut self, point: C) -> io::Result<()> {
|
fn common_point(&mut self, point: C) -> io::Result<()> {
|
||||||
let (x, y) = Option::from(point.get_xy()).ok_or(io::Error::new(
|
let (x, y) = Option::from(point.get_xy()).ok_or_else(|| {
|
||||||
|
io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
"cannot write points at infinity to the transcript",
|
"cannot write points at infinity to the transcript",
|
||||||
))?;
|
)
|
||||||
|
})?;
|
||||||
self.base_state += &(x * &C::Base::ZETA);
|
self.base_state += &(x * &C::Base::ZETA);
|
||||||
self.base_state = self.base_state.square();
|
self.base_state = self.base_state.square();
|
||||||
self.base_state += &(y * &C::Base::ZETA);
|
self.base_state += &(y * &C::Base::ZETA);
|
||||||
|
|
Loading…
Reference in New Issue