Skip to content

Commit

Permalink
Add tests for Asn1Integer comparison and to_owned
Browse files Browse the repository at this point in the history
  • Loading branch information
Skepfyr committed Mar 28, 2023
1 parent a888f7a commit 516f1b5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions openssl/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,28 @@ mod tests {
assert!(c_ref < a_ref);
}

#[test]
fn integer_to_owned() {
let a = Asn1Integer::from_bn(&BigNum::from_dec_str("42").unwrap()).unwrap();
let b = a.to_owned().unwrap();
assert_eq!(
a.to_bn().unwrap().to_dec_str().unwrap().to_string(),
b.to_bn().unwrap().to_dec_str().unwrap().to_string(),
);
assert_ne!(a.as_ptr(), b.as_ptr());
}

#[test]
fn integer_cmp() {
let a = Asn1Integer::from_bn(&BigNum::from_dec_str("42").unwrap()).unwrap();
let b = Asn1Integer::from_bn(&BigNum::from_dec_str("42").unwrap()).unwrap();
let c = Asn1Integer::from_bn(&BigNum::from_dec_str("43").unwrap()).unwrap();
assert!(a == b);
assert!(a != c);
assert!(a < c);
assert!(c > b);
}

#[test]
fn object_from_str() {
let object = Asn1Object::from_str("2.16.840.1.101.3.4.2.1").unwrap();
Expand Down

0 comments on commit 516f1b5

Please sign in to comment.