Skip to content

Commit

Permalink
fixed clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
CluEleSsUK committed Aug 30, 2023
1 parent b5e6cf8 commit 499e14a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ pub struct DrandClient<'a, T: Transport> {
chain_info: ChainInfo,
}

fn new_http_client(base_url: &str) -> Result<DrandClient<HttpTransport>, DrandClientError> {
pub fn new_http_client(base_url: &str) -> Result<DrandClient<HttpTransport>, DrandClientError> {
let http_transport = new_http_transport();
let chain_info = fetch_chain_info(&http_transport, base_url)?;
return Ok(DrandClient {
Ok(DrandClient {
base_url,
transport: http_transport,
chain_info,
});
})
}

pub trait Transport {
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<'a, T: Transport> DrandClient<'a, T> {
&self.chain_info.public_key,
&beacon,
)
.map_err(|_| DrandClientError::FailedVerification)?;
.map_err(|_| DrandClientError::FailedVerification)?;
Ok(beacon)
}
Err(_) => Err(DrandClientError::InvalidBeacon),
Expand Down
32 changes: 16 additions & 16 deletions src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'de> Deserialize<'de> for SchemeID {
"bls-unchained-on-g1" => Ok(SchemeID::UnchainedOnG1),
"bls-unchained-g1-rfc9380" => Ok(SchemeID::UnchainedOnG1RFC9380),
_ => Err(serde::de::Error::unknown_variant(
&s,
s,
&[
"pedersen-bls-chained",
"pedersen-bls-unchained",
Expand Down Expand Up @@ -72,10 +72,10 @@ pub enum VerificationError {
InvalidRandomness,
}

pub fn verify_beacon<'a>(
pub fn verify_beacon(
scheme_id: &SchemeID,
public_key: &[u8],
beacon: &'a Beacon,
beacon: &Beacon,
) -> Result<(), VerificationError> {
if Sha256::digest(&beacon.signature).to_vec() != beacon.randomness {
return Err(VerificationError::InvalidRandomness);
Expand Down Expand Up @@ -108,28 +108,28 @@ pub fn verify_beacon<'a>(
}
}

fn unchained_beacon_message<'a>(beacon: &Beacon) -> Result<Vec<u8>, VerificationError> {
if beacon.previous_signature.len() > 0 {
fn unchained_beacon_message(beacon: &Beacon) -> Result<Vec<u8>, VerificationError> {
if !beacon.previous_signature.is_empty() {
return Err(VerificationError::UnchainedHasPreviousSignature);
}
let round_bytes = beacon.round_number.to_be_bytes();

Ok(Sha256::digest(&round_bytes).to_vec())
}

fn chained_beacon_message<'a>(beacon: &Beacon) -> Result<Vec<u8>, VerificationError> {
if beacon.previous_signature.len() == 0 {
fn chained_beacon_message(beacon: &Beacon) -> Result<Vec<u8>, VerificationError> {
if beacon.previous_signature.is_empty() {
Err(VerificationError::ChainedBeaconNeedsPreviousSignature)
} else {
// surely there's a better way to concat two slices
let mut message = Vec::new();
message.extend_from_slice(&beacon.previous_signature.as_slice());
message.extend_from_slice(beacon.previous_signature.as_slice());
message.extend_from_slice(&beacon.round_number.to_be_bytes());
Ok(Sha256::digest(message.as_slice()).to_vec())
}
}

pub fn verify_on_g2<'a>(
pub fn verify_on_g2(
public_key: &[u8],
message: &[u8],
signature: &[u8],
Expand All @@ -155,16 +155,16 @@ pub fn verify_on_g2<'a>(
return Err(VerificationError::InvalidPublicKey);
}

if message.len() == 0 {
if message.is_empty() {
return Err(VerificationError::EmptyMessage);
}

if signature.len() == 0 {
if signature.is_empty() {
return Err(VerificationError::InvalidSignatureLength);
}

let m = <G2Projective as HashToCurve<ExpandMsgXmd<Sha256>>>::hash_to_curve(
&message,
message,
domain_separation_tag.as_bytes(),
);

Expand All @@ -182,7 +182,7 @@ pub fn verify_on_g2<'a>(
}
}

pub fn verify_on_g1<'a>(
pub fn verify_on_g1(
public_key: &[u8],
message: &[u8],
signature: &[u8],
Expand All @@ -207,16 +207,16 @@ pub fn verify_on_g1<'a>(
return Err(VerificationError::InvalidPublicKey);
}

if message.len() == 0 {
if message.is_empty() {
return Err(VerificationError::EmptyMessage);
}

if signature.len() == 0 {
if signature.is_empty() {
return Err(VerificationError::InvalidSignatureLength);
}

let m = <G1Projective as HashToCurve<ExpandMsgXmd<Sha256>>>::hash_to_curve(
&message,
message,
domain_separation_tag.as_bytes(),
);

Expand Down

0 comments on commit 499e14a

Please sign in to comment.