Skip to content

Commit

Permalink
add signing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Oct 24, 2024
1 parent 74aee3f commit 127796c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
18 changes: 18 additions & 0 deletions crates/xdid-method-key/src/keys/p384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ impl Multicodec for P384Codec {

#[cfg(test)]
mod tests {
use ring::signature::{VerificationAlgorithm, ECDSA_P384_SHA384_ASN1};

use crate::parser::DidKeyParser;

use super::*;
Expand Down Expand Up @@ -123,4 +125,20 @@ mod tests {
let parser = DidKeyParser::default();
let _ = parser.parse(&did).unwrap();
}

#[test]
fn test_sign() {
let pair = P384KeyPair::generate();

let msg = vec![0, 1, 2, 3, 4, 5, 6, 7, 8];
let signature = pair.sign(&msg).unwrap();

assert!(ECDSA_P384_SHA384_ASN1
.verify(
pair.public_bytes().to_vec().as_slice().into(),
msg.as_slice().into(),
signature.as_slice().into()
)
.is_ok());
}
}
20 changes: 19 additions & 1 deletion crates/xdid-method-key/src/keys/p521.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ impl Multicodec for P521Codec {

#[cfg(test)]
mod tests {
use crate::parser::DidKeyParser;
use ring::signature::{VerificationAlgorithm, ECDSA_P384_SHA384_ASN1};

use crate::{p384::P384KeyPair, parser::DidKeyParser};

use super::*;

Expand Down Expand Up @@ -123,4 +125,20 @@ mod tests {
let parser = DidKeyParser::default();
let _ = parser.parse(&did).unwrap();
}

#[test]
fn test_sign() {
let pair = P384KeyPair::generate();

let msg = vec![0, 1, 2, 3, 4, 5, 6, 7, 8];
let signature = pair.sign(&msg).unwrap();

assert!(ECDSA_P384_SHA384_ASN1
.verify(
pair.public_bytes().to_vec().as_slice().into(),
msg.as_slice().into(),
signature.as_slice().into()
)
.is_ok());
}
}

0 comments on commit 127796c

Please sign in to comment.