mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Use ok_or_else instead of ok_or in serde decoding (#382)
Serde errors are not simple enums; they format a full error string from their arguments. It's worth not doing that up front.
This commit is contained in:
parent
67b8c2e40c
commit
a63e14f4de
3 changed files with 7 additions and 7 deletions
|
|
@ -288,11 +288,11 @@ impl<'de> Deserialize<'de> for EdwardsPoint {
|
|||
for i in 0..32 {
|
||||
bytes[i] = seq
|
||||
.next_element()?
|
||||
.ok_or(serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
}
|
||||
CompressedEdwardsY(bytes)
|
||||
.decompress()
|
||||
.ok_or(serde::de::Error::custom("decompression failed"))
|
||||
.ok_or_else(|| serde::de::Error::custom("decompression failed"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -323,7 +323,7 @@ impl<'de> Deserialize<'de> for CompressedEdwardsY {
|
|||
for i in 0..32 {
|
||||
bytes[i] = seq
|
||||
.next_element()?
|
||||
.ok_or(serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
}
|
||||
Ok(CompressedEdwardsY(bytes))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -409,11 +409,11 @@ impl<'de> Deserialize<'de> for RistrettoPoint {
|
|||
for i in 0..32 {
|
||||
bytes[i] = seq
|
||||
.next_element()?
|
||||
.ok_or(serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
}
|
||||
CompressedRistretto(bytes)
|
||||
.decompress()
|
||||
.ok_or(serde::de::Error::custom("decompression failed"))
|
||||
.ok_or_else(|| serde::de::Error::custom("decompression failed"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -444,7 +444,7 @@ impl<'de> Deserialize<'de> for CompressedRistretto {
|
|||
for i in 0..32 {
|
||||
bytes[i] = seq
|
||||
.next_element()?
|
||||
.ok_or(serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
}
|
||||
Ok(CompressedRistretto(bytes))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -478,7 +478,7 @@ impl<'de> Deserialize<'de> for Scalar {
|
|||
for i in 0..32 {
|
||||
bytes[i] = seq
|
||||
.next_element()?
|
||||
.ok_or(serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
|
||||
}
|
||||
Option::from(Scalar::from_canonical_bytes(bytes))
|
||||
.ok_or_else(|| serde::de::Error::custom(&"scalar was not canonically encoded"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue