Skip to content

Commit

Permalink
seals: fix verify API to avoid Result<bool>
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 29, 2023
1 parent b853c22 commit 5d1e058
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
24 changes: 8 additions & 16 deletions single_use_seals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub trait SealWitness<Seal> {

/// Verifies that the seal was indeed closed over the message with the
/// provided seal closure witness.
fn verify_seal(&self, seal: &Seal, msg: &Self::Message) -> Result<bool, Self::Error>;
fn verify_seal(&self, seal: &Seal, msg: &Self::Message) -> Result<(), Self::Error>;

/// Performs batch verification of the seals.
///
Expand All @@ -275,16 +275,14 @@ pub trait SealWitness<Seal> {
&self,
seals: impl IntoIterator<Item = &'seal Seal>,
msg: &Self::Message,
) -> Result<bool, Self::Error>
) -> Result<(), Self::Error>

Check warning on line 278 in single_use_seals/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

single_use_seals/src/lib.rs#L278

Added line #L278 was not covered by tests
where
Seal: 'seal,
{
for seal in seals {
if !self.verify_seal(seal, msg)? {
return Ok(false);
}
self.verify_seal(seal, msg)?;

Check warning on line 283 in single_use_seals/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

single_use_seals/src/lib.rs#L283

Added line #L283 was not covered by tests
}
Ok(true)
Ok(())

Check warning on line 285 in single_use_seals/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

single_use_seals/src/lib.rs#L285

Added line #L285 was not covered by tests
}
}

Expand Down Expand Up @@ -436,11 +434,7 @@ where Seal: Sync + Send

/// Verifies that the seal was indeed closed over the message with the
/// provided seal closure witness.
async fn verify_seal_async(
&self,
seal: &Seal,
msg: &Self::Message,
) -> Result<bool, Self::Error>;
async fn verify_seal_async(&self, seal: &Seal, msg: &Self::Message) -> Result<(), Self::Error>;

/// Performs batch verification of the seals.
///
Expand All @@ -451,18 +445,16 @@ where Seal: Sync + Send
&self,
seals: I,
msg: &Self::Message,
) -> Result<bool, Self::Error>
) -> Result<(), Self::Error>

Check warning on line 448 in single_use_seals/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

single_use_seals/src/lib.rs#L448

Added line #L448 was not covered by tests
where
I: IntoIterator<Item = &'seal Seal> + Send,
I::IntoIter: Send,
Seal: 'seal,
{
for seal in seals {
if !self.verify_seal_async(seal, msg).await? {
return Ok(false);
}
self.verify_seal_async(seal, msg).await?;

Check warning on line 455 in single_use_seals/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

single_use_seals/src/lib.rs#L455

Added line #L455 was not covered by tests
}
return Ok(true);
return Ok(());

Check warning on line 457 in single_use_seals/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

single_use_seals/src/lib.rs#L457

Added line #L457 was not covered by tests
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ mod test {
type Message = Vec<u8>;
type Error = Issue;

fn verify_seal(&self, _seal: &Seal, _msg: &Self::Message) -> Result<bool, Self::Error> {
Ok(true)
fn verify_seal(&self, _seal: &Seal, _msg: &Self::Message) -> Result<(), Self::Error> {
Ok(())

Check warning on line 428 in src/api.rs

View check run for this annotation

Codecov / codecov/patch

src/api.rs#L428

Added line #L428 was not covered by tests
}
}

Expand Down

0 comments on commit 5d1e058

Please sign in to comment.