-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
433f3cb
commit 4c4d4e4
Showing
13 changed files
with
597 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
rust/rbac-registration/src/cardano/cip509/types/tx_input_hash.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
rust/rbac-registration/src/cardano/cip509/types/validation_signature.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use anyhow::{anyhow, Error}; | ||
|
||
/// A validation signature. | ||
/// | ||
/// The signature must be at least 1 byte and at most 64 bytes long. | ||
#[derive(Debug, Eq, PartialEq, Clone)] | ||
pub struct ValidationSignature(Vec<u8>); | ||
|
||
impl TryFrom<Vec<u8>> for ValidationSignature { | ||
type Error = Error; | ||
|
||
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> { | ||
if value.is_empty() || value.len() > 64 { | ||
return Err(anyhow!("Invalid length ({}), 1..=64 expected", value.len())); | ||
} | ||
|
||
Ok(Self(value)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn invalid_length() { | ||
let error = ValidationSignature::try_from(Vec::new()).unwrap_err(); | ||
assert!(format!("{error}").starts_with("Invalid length")); | ||
|
||
let error = ValidationSignature::try_from(vec![0; 65]).unwrap_err(); | ||
assert!(format!("{error}").starts_with("Invalid length")); | ||
} | ||
} |
Oops, something went wrong.