Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silly refactor for more idiomatic Rust style #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions contracts/dkg_coordinator/src/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ impl<'de> Deserialize<'de> for G2Element {
{
let s = String::deserialize(deserializer)?;
let decoded = BASE64_STANDARD.decode(&s).map_err(D::Error::custom)?;
if decoded.len() != G2_ELEMENT_BYTE_LENGTH {
return Err(D::Error::custom(format!(
"Invalid length for G2Element: expected {}, got {}",
G2_ELEMENT_BYTE_LENGTH,
decoded.len()
)));
match decoded.len() {
G2_ELEMENT_BYTE_LENGTH => Ok(G2Element(decoded)),
len => Err(D::Error::custom(
format_args!(
"Invalid length for G2Element: expected {}, got {}",
G2_ELEMENT_BYTE_LENGTH, len
)
.to_string(),
)),
}
Ok(G2Element(decoded))
}
}

Expand All @@ -116,14 +118,16 @@ impl<'de> Deserialize<'de> for Scalar {
{
let s = String::deserialize(deserializer)?;
let decoded = BASE64_STANDARD.decode(&s).map_err(D::Error::custom)?;
if decoded.len() != SCALAR_LENGTH {
return Err(D::Error::custom(format!(
"Invalid length for Scalar: expected {}, got {}",
SCALAR_LENGTH,
decoded.len()
)));
match decoded.len() {
SCALAR_LENGTH => Ok(Scalar(decoded)),
len => Err(D::Error::custom(
format_args!(
"Invalid length for Scalar: expected {}, got {}",
SCALAR_LENGTH, len
)
.to_string(),
)),
}
Ok(Scalar(decoded))
}
}

Expand Down