@@ -3,14 +3,14 @@ use std::{
33 process:: { Command , Stdio } ,
44} ;
55
6- use anyhow:: { Context , bail} ;
76use openssl:: { pkcs12:: Pkcs12 , x509:: X509 } ;
7+ use snafu:: { OptionExt , ResultExt , whatever} ;
88use stackable_secret_operator_utils:: pem:: split_pem_certificates;
99
10- pub fn parse_pem_contents ( pem_bytes : & [ u8 ] ) -> anyhow :: Result < Vec < X509 > > {
10+ pub fn parse_pem_contents ( pem_bytes : & [ u8 ] ) -> Result < Vec < X509 > , snafu :: Whatever > {
1111 let pems = split_pem_certificates ( pem_bytes) ;
1212 pems. into_iter ( )
13- . map ( |pem| X509 :: from_pem ( pem) . context ( "failed to parse PEM encoded certificate" ) )
13+ . map ( |pem| X509 :: from_pem ( pem) . whatever_context ( "failed to parse PEM encoded certificate" ) )
1414 . collect ( )
1515}
1616
@@ -44,15 +44,18 @@ pub fn parse_pem_contents(pem_bytes: &[u8]) -> anyhow::Result<Vec<X509>> {
4444/// The proper solution would be that secret-operator writes PKCS12 truststores using modern algorithms.
4545/// For that we probably(?) drop the p12 crate?
4646#[ allow( unused) ]
47- pub fn parse_pkcs12_file ( file_contents : & [ u8 ] , password : & str ) -> anyhow:: Result < Vec < X509 > > {
47+ pub fn parse_pkcs12_file (
48+ file_contents : & [ u8 ] ,
49+ password : & str ,
50+ ) -> Result < Vec < X509 > , snafu:: Whatever > {
4851 let parsed = Pkcs12 :: from_der ( file_contents)
49- . context ( "failed to parse PKCS12 DER encoded file" ) ?
52+ . whatever_context ( "failed to parse PKCS12 DER encoded file" ) ?
5053 . parse2 ( password)
51- . context ( "Failed to parse PKCS12 using the provided password" ) ?;
54+ . whatever_context ( "Failed to parse PKCS12 using the provided password" ) ?;
5255
5356 parsed
5457 . ca
55- . context ( "pkcs12 truststore did not contain a CA" ) ?
58+ . whatever_context ( "pkcs12 truststore did not contain a CA" ) ?
5659 . into_iter ( )
5760 . map ( Ok )
5861 . collect ( )
@@ -64,7 +67,7 @@ pub fn parse_pkcs12_file(file_contents: &[u8], password: &str) -> anyhow::Result
6467pub fn parse_pkcs12_file_workaround (
6568 file_contents : & [ u8 ] ,
6669 password : & str ,
67- ) -> anyhow :: Result < Vec < X509 > > {
70+ ) -> Result < Vec < X509 > , snafu :: Whatever > {
6871 let mut child = Command :: new ( "openssl" )
6972 . args ( & [
7073 "pkcs12" ,
@@ -78,27 +81,27 @@ pub fn parse_pkcs12_file_workaround(
7881 . stdout ( Stdio :: piped ( ) )
7982 . stderr ( Stdio :: piped ( ) )
8083 . spawn ( )
81- . context ( "Failed to spawn openssl process" ) ?;
84+ . whatever_context ( "Failed to spawn openssl process" ) ?;
8285
8386 {
8487 let stdin = child
8588 . stdin
8689 . as_mut ( )
87- . context ( "Failed to open openssl process stdin" ) ?;
90+ . whatever_context ( "Failed to open openssl process stdin" ) ?;
8891 stdin
8992 . write_all ( file_contents)
90- . context ( "Failed to write PKCS12 data to openssl process stdin" ) ?;
93+ . whatever_context ( "Failed to write PKCS12 data to openssl process stdin" ) ?;
9194 }
9295
9396 let output = child
9497 . wait_with_output ( )
95- . context ( "Failed to read openssl process output" ) ?;
98+ . whatever_context ( "Failed to read openssl process output" ) ?;
9699 if !output. status . success ( ) {
97100 let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
98- bail ! ( "openssl process failed with STDERR: {stderr:?}" ) ;
101+ whatever ! ( "openssl process failed with STDERR: {stderr:?}" ) ;
99102 }
100103
101- parse_pem_contents ( & output. stdout ) . with_context ( | | {
104+ parse_pem_contents ( & output. stdout ) . with_whatever_context ( |_ | {
102105 format ! (
103106 "failed to parse openssl process output, which should be PEM. STDOUT: {stdout}?" ,
104107 stdout = String :: from_utf8_lossy( & output. stdout)
0 commit comments