File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,11 @@ impl Certificate {
200200 Ok ( Certificate ( cert) )
201201 }
202202
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+
203208 pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
204209 let der = self . 0 . to_der ( ) ?;
205210 Ok ( der)
Original file line number Diff line number Diff line change @@ -172,6 +172,13 @@ impl Certificate {
172172 }
173173 }
174174
175+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > , Error > {
176+ pem:: PemBlock :: new ( buf)
177+ . iter ( )
178+ . map ( |pem| CertContext :: from_pem ( pem) . map ( Certificate ) )
179+ . collect ( )
180+ }
181+
175182 pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
176183 Ok ( self . 0 . to_der ( ) . to_vec ( ) )
177184 }
Original file line number Diff line number Diff line change @@ -219,6 +219,22 @@ impl Certificate {
219219 panic ! ( "Not implemented on iOS" ) ;
220220 }
221221
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+
222238 pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
223239 Ok ( self . 0 . to_der ( ) )
224240 }
Original file line number Diff line number Diff line change @@ -209,6 +209,12 @@ impl Certificate {
209209 Ok ( Certificate ( cert) )
210210 }
211211
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+
212218 /// Returns the DER-encoded representation of this certificate.
213219 pub fn to_der ( & self ) -> Result < Vec < u8 > > {
214220 let der = self . 0 . to_der ( ) ?;
You can’t perform that action at this time.
0 commit comments