Skip to content

Commit 00ba4b7

Browse files
author
Jonas Maier
committed
methods to fetch timestamp from timestamp response object
1 parent e7b4565 commit 00ba4b7

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

openssl-sys/src/ts.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ use crate::{
44
ASN1_INTEGER, ASN1_OBJECT, ASN1_OCTET_STRING, BIO, EVP_MD, EVP_PKEY, X509, X509_ALGOR,
55
};
66

7+
use super::ASN1_STRING;
8+
79
pub enum TS_MSG_IMPRINT {}
810
pub enum TS_REQ {}
911
pub enum TS_RESP {}
12+
pub enum TS_TST_INFO {}
1013
pub enum TS_RESP_CTX {}
1114

1215
cfg_if! {
@@ -107,6 +110,10 @@ extern "C" {
107110
pub fn TS_RESP_CTX_add_md(ctx: *mut TS_RESP_CTX, md: *const EVP_MD) -> c_int;
108111

109112
pub fn TS_RESP_create_response(ctx: *mut TS_RESP_CTX, req_bio: *mut BIO) -> *mut TS_RESP;
113+
114+
pub fn TS_RESP_get_tst_info(a: *mut TS_RESP) -> *mut TS_TST_INFO;
115+
pub fn TS_TST_INFO_get_time(a: *const TS_TST_INFO) -> *const ASN1_STRING;
116+
pub fn TS_TST_INFO_free(a: *mut TS_TST_INFO);
110117
}
111118

112119
cfg_if! {

openssl/src/ts.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use openssl_macros::corresponds;
1111
use std::convert::TryFrom;
1212
use std::ptr;
1313

14-
use crate::asn1::{Asn1IntegerRef, Asn1ObjectRef, Asn1OctetString};
14+
use crate::asn1::{Asn1IntegerRef, Asn1ObjectRef, Asn1OctetString, Asn1StringRef};
1515
use crate::bio::MemBioSlice;
1616
use crate::error::ErrorStack;
1717
use crate::hash::{Hasher, MessageDigest};
1818
use crate::pkey::{HasPrivate, PKeyRef};
19-
use crate::util::ForeignTypeExt;
19+
use crate::util::{ForeignTypeExt, ForeignTypeRefExt};
2020
use crate::x509::{X509Algorithm, X509AlgorithmRef, X509Ref};
2121
use crate::{cvt, cvt_p};
2222

@@ -243,6 +243,19 @@ impl TsRespRef {
243243
.map(|_| ())
244244
}
245245
}
246+
247+
// idk what the null-ness guarantees of this function is as it's not documented in openssl
248+
#[corresponds(TS_RESP_get_tst_info)]
249+
pub fn get_tst(&self) -> Option<&TsTstInfoRef> {
250+
unsafe {
251+
let info = ffi::TS_RESP_get_tst_info(self.as_ptr());
252+
if info.is_null() {
253+
None
254+
} else {
255+
Some(TsTstInfoRef::from_const_ptr(info))
256+
}
257+
}
258+
}
246259
}
247260

248261
bitflags! {
@@ -397,6 +410,28 @@ impl TsRespContext {
397410
}
398411
}
399412

413+
foreign_type_and_impl_send_sync!{
414+
type CType = ffi::TS_TST_INFO;
415+
fn drop = ffi::TS_TST_INFO_free;
416+
pub struct TsTstInfo;
417+
pub struct TsTstInfoRef;
418+
}
419+
420+
impl TsTstInfoRef {
421+
// idk what the null-ness guarantees of this function is as it's not documented in openssl
422+
#[corresponds(TS_TST_INFO_get_time)]
423+
pub fn get_time(&self) -> Option<&Asn1StringRef> {
424+
unsafe {
425+
let ptr = ffi::TS_TST_INFO_get_time(self.as_ptr());
426+
if ptr.is_null() {
427+
None
428+
} else {
429+
Some(Asn1StringRef::from_const_ptr(ptr))
430+
}
431+
}
432+
}
433+
}
434+
400435
#[cfg(test)]
401436
mod tests {
402437
use super::*;

0 commit comments

Comments
 (0)