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

Constrain signature to bytes #10

Merged
merged 1 commit into from
Mar 29, 2022
Merged
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
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,23 @@ pub enum VerificationError {
NotCurrentlyValid,
}

pub struct BasicSignature<S> {
pub struct BasicSignature<S: AsRef<[u8]> + TryFrom<Vec<u8>>> {
Copy link
Contributor

@chunningham chunningham Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense according to the spec 👍, I would prefer to avoid the S :DagCbor bound in #7, but its not possible I think :(

pub s: S,
}

impl<S: AsRef<[u8]> + TryFrom<Vec<u8>>> AsRef<[u8]> for BasicSignature<S> {
fn as_ref(&self) -> &[u8] {
self.s.as_ref()
}
}

impl<S: AsRef<[u8]> + TryFrom<Vec<u8>>> TryFrom<Vec<u8>> for BasicSignature<S> {
type Error = <S as TryFrom<Vec<u8>>>::Error;
fn try_from(s: Vec<u8>) -> Result<Self, Self::Error> {
Ok(Self { s: s.try_into()? })
}
}

#[derive(Copy, Clone)]
pub enum Version {
V1 = 1,
Expand Down