File tree 3 files changed +27
-0
lines changed
3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,11 @@ impl Certificate {
200
200
Ok ( Certificate ( cert) )
201
201
}
202
202
203
+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > , Error > {
204
+ let mut certs = X509 :: stack_from_pem ( buf) ?;
205
+ Ok ( certs. drain ( ..) . map ( Certificate ) . collect ( ) )
206
+ }
207
+
203
208
pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
204
209
let der = self . 0 . to_der ( ) ?;
205
210
Ok ( der)
Original file line number Diff line number Diff line change @@ -219,6 +219,22 @@ impl Certificate {
219
219
panic ! ( "Not implemented on iOS" ) ;
220
220
}
221
221
222
+ #[ cfg( not( target_os = "ios" ) ) ]
223
+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > , Error > {
224
+ let mut items = SecItems :: default ( ) ;
225
+ ImportOptions :: new ( ) . items ( & mut items) . import ( buf) ?;
226
+ if items. identities . is_empty ( ) && items. keys . is_empty ( ) {
227
+ Ok ( items. certificates . drain ( ..) . map ( Certificate ) . collect ( ) )
228
+ } else {
229
+ Err ( Error ( base:: Error :: from ( errSecParam) ) )
230
+ }
231
+ }
232
+
233
+ #[ cfg( target_os = "ios" ) ]
234
+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > , Error > {
235
+ panic ! ( "Not implemented on iOS" ) ;
236
+ }
237
+
222
238
pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
223
239
Ok ( self . 0 . to_der ( ) )
224
240
}
Original file line number Diff line number Diff line change @@ -209,6 +209,12 @@ impl Certificate {
209
209
Ok ( Certificate ( cert) )
210
210
}
211
211
212
+ /// Parses some PEM-formatted X509 certificates.
213
+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > > {
214
+ let mut certs = imp:: Certificate :: stack_from_pem ( buf) ?;
215
+ Ok ( certs. drain ( ..) . map ( Certificate ) . collect ( ) )
216
+ }
217
+
212
218
/// Returns the DER-encoded representation of this certificate.
213
219
pub fn to_der ( & self ) -> Result < Vec < u8 > > {
214
220
let der = self . 0 . to_der ( ) ?;
You can’t perform that action at this time.
0 commit comments