@@ -101,29 +101,27 @@ impl Identity {
101
101
pub fn from_pkcs8 ( pem : & [ u8 ] , key : & [ u8 ] ) -> Result < Identity , Error > {
102
102
let mut store = Memory :: new ( ) ?. into_store ( ) ;
103
103
let mut cert_iter = crate :: pem:: PemBlock :: new ( pem) . into_iter ( ) ;
104
- let leaf = cert_iter. next ( ) . unwrap ( ) ;
105
- let cert = CertContext :: from_pem ( std:: str:: from_utf8 ( leaf) . unwrap ( ) ) . unwrap ( ) ;
104
+ let leaf = cert_iter. next ( ) . expect ( "at least one certificate must be provided to create an identity" ) ;
105
+ let cert = CertContext :: from_pem ( std:: str:: from_utf8 ( leaf) . map_err ( |_| io :: Error :: new ( io :: ErrorKind :: InvalidInput , "leaf cert contains invalid utf8" ) ) ? ) ? ;
106
106
107
107
let mut options = AcquireOptions :: new ( ) ;
108
108
options. container ( "schannel" ) ;
109
109
let type_ = ProviderType :: rsa_full ( ) ;
110
110
111
111
let mut container = match options. acquire ( type_) {
112
112
Ok ( container) => container,
113
- Err ( _) => options. new_keyset ( true ) . acquire ( type_) . unwrap ( ) ,
113
+ Err ( _) => options. new_keyset ( true ) . acquire ( type_) ? ,
114
114
} ;
115
- let key = crate :: pem:: pem_to_der ( key, Some ( crate :: pem:: PEM_PRIVATE_KEY ) ) . unwrap ( ) ;
115
+ let key = crate :: pem:: pem_to_der ( key, Some ( crate :: pem:: PEM_PRIVATE_KEY ) ) . expect ( "invalid PKCS8 key provided" ) ;
116
116
container. import ( )
117
- . import_pkcs8 ( & key)
118
- . unwrap ( ) ;
117
+ . import_pkcs8 ( & key) ?;
119
118
120
119
cert. set_key_prov_info ( )
121
120
. container ( "schannel" )
122
121
. type_ ( type_)
123
122
. keep_open ( true )
124
123
. key_spec ( KeySpec :: key_exchange ( ) )
125
- . set ( )
126
- . unwrap ( ) ;
124
+ . set ( ) ?;
127
125
let mut context = store. add_cert ( & cert, CertAdd :: Always ) ?;
128
126
129
127
for int_cert in cert_iter {
0 commit comments