-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
2 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use asn1_rs::*; | ||
use hex_literal::hex; | ||
|
||
#[derive(Debug, PartialEq, DerSequence, ToDerSequence)] | ||
#[debug_derive] | ||
pub struct T1<'a> { | ||
a: u32, | ||
b: u16, | ||
c: u16, | ||
d: &'a str, | ||
} | ||
|
||
#[test] | ||
fn toder_sequence_lifetime() { | ||
let input = &hex!("300f0201 01020102 020103 0c0461626364"); | ||
let (rem, t1) = T1::from_der(input).expect("parsing failed"); | ||
assert!(rem.is_empty()); | ||
assert_eq!( | ||
t1, | ||
T1 { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: "abcd" | ||
} | ||
); | ||
// serialize back data | ||
let output = t1.to_der_vec().expect("serialization failed"); | ||
assert_eq!(&input[..], output); | ||
} |
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,21 @@ | ||
use asn1_rs::*; | ||
use hex_literal::hex; | ||
|
||
#[derive(Debug, PartialEq, DerSequence, ToDerSequence)] | ||
#[debug_derive] | ||
pub struct T1 { | ||
a: u32, | ||
b: u16, | ||
c: u16, | ||
} | ||
|
||
#[test] | ||
fn toder_sequence() { | ||
let input = &hex!("30090201 01020102 020103"); | ||
let (rem, t1) = T1::from_der(input).expect("parsing failed"); | ||
assert!(rem.is_empty()); | ||
assert_eq!(t1, T1 { a: 1, b: 2, c: 3 }); | ||
// serialize back data | ||
let output = t1.to_der_vec().expect("serialization failed"); | ||
assert_eq!(&input[..], output); | ||
} |