From 287405e5361123337f6c156d60e69d0f925fa499 Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Fri, 16 Sep 2022 17:15:21 -0400 Subject: [PATCH] Trying a struct for attest response Signed-off-by: Richard Zak --- src/main.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2fb74d6f..8b885422 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,7 +42,7 @@ use const_oid::db::rfc5280::{ }; use const_oid::db::rfc5912::ID_EXTENSION_REQ; use der::asn1::{GeneralizedTime, Ia5StringRef, UIntRef}; -use der::{Decode, Encode}; +use der::{Decode, Encode, Sequence}; use pkcs8::PrivateKeyInfo; use x509::ext::pkix::{BasicConstraints, ExtendedKeyUsage, KeyUsage, KeyUsages, SubjectAltName}; use x509::name::RdnSequence; @@ -93,6 +93,15 @@ struct State { san: Option, } +#[derive(Clone, Debug, Default, Sequence)] +struct Output<'a> { + /// The signing certificate chain back to the root. + pub chain: Vec>, + + /// All issued certificates. + pub issued: Vec>, +} + impl State { pub fn load( san: Option, @@ -274,7 +283,11 @@ async fn attest( return Err(StatusCode::BAD_REQUEST); } }; - let mut vec_return: Vec> = Vec::new(); + + let mut response = Output { + chain: vec![issuer.clone()], + issued: Vec::new(), + }; // Decode and verify the certification request. // let cr = CertReq::from_der(body.as_ref()).or(Err(StatusCode::BAD_REQUEST))?; @@ -377,10 +390,9 @@ async fn attest( let crt = Certificate::from_der(&crt).or(Err(ISE))?; // Create and return the PkiPath. - let pkipath: Vec = vec![issuer, crt].to_vec().unwrap(); - vec_return.push(pkipath.to_vec().or(Err(ISE))?); + response.issued.push(crt); } - Ok(vec_return.to_vec().or(Err(ISE))?) + Ok(response.to_vec().or(Err(ISE))?) } #[cfg(test)]