Update
This commit is contained in:
24
central_backend/src/crypto/openssl_utils.rs
Normal file
24
central_backend/src/crypto/openssl_utils.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use openssl::asn1::{Asn1Time, Asn1TimeRef};
|
||||
|
||||
/// Clone Asn1 time
|
||||
pub fn clone_asn1_time(time: &Asn1TimeRef) -> anyhow::Result<Asn1Time> {
|
||||
let diff = time.diff(Asn1Time::from_unix(0)?.as_ref())?;
|
||||
let days = diff.days.abs();
|
||||
let secs = diff.secs.abs();
|
||||
|
||||
Ok(Asn1Time::from_unix((days * 3600 * 24 + secs) as i64)?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::crypto::openssl_utils::clone_asn1_time;
|
||||
use openssl::asn1::Asn1Time;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[test]
|
||||
fn test_clone_asn1_time() {
|
||||
let a = Asn1Time::from_unix(10).unwrap();
|
||||
let b = clone_asn1_time(a.as_ref()).unwrap();
|
||||
assert_eq!(a.compare(&b).unwrap(), Ordering::Equal);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user