File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,11 @@ impl Certificate {
177177 Ok ( Certificate ( cert) )
178178 }
179179
180+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > , Error > {
181+ let mut certs = X509 :: stack_from_pem ( buf) ?;
182+ Ok ( certs. drain ( ..) . map ( Certificate ) . collect ( ) )
183+ }
184+
180185 pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
181186 let der = self . 0 . to_der ( ) ?;
182187 Ok ( der)
Original file line number Diff line number Diff line change @@ -167,6 +167,22 @@ impl Certificate {
167167 panic ! ( "Not implemented on iOS" ) ;
168168 }
169169
170+ #[ cfg( not( target_os = "ios" ) ) ]
171+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > , Error > {
172+ let mut items = SecItems :: default ( ) ;
173+ ImportOptions :: new ( ) . items ( & mut items) . import ( buf) ?;
174+ if items. identities . is_empty ( ) && items. keys . is_empty ( ) {
175+ Ok ( items. certificates . drain ( ..) . map ( Certificate ) . collect ( ) )
176+ } else {
177+ Err ( Error ( base:: Error :: from ( errSecParam) ) )
178+ }
179+ }
180+
181+ #[ cfg( target_os = "ios" ) ]
182+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > , Error > {
183+ panic ! ( "Not implemented on iOS" ) ;
184+ }
185+
170186 pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
171187 Ok ( self . 0 . to_der ( ) )
172188 }
Original file line number Diff line number Diff line change @@ -198,6 +198,12 @@ impl Certificate {
198198 Ok ( Certificate ( cert) )
199199 }
200200
201+ /// Parses some PEM-formatted X509 certificates.
202+ pub fn stack_from_pem ( buf : & [ u8 ] ) -> Result < Vec < Certificate > > {
203+ let mut certs = imp:: Certificate :: stack_from_pem ( buf) ?;
204+ Ok ( certs. drain ( ..) . map ( Certificate ) . collect ( ) )
205+ }
206+
201207 /// Returns the DER-encoded representation of this certificate.
202208 pub fn to_der ( & self ) -> Result < Vec < u8 > > {
203209 let der = self . 0 . to_der ( ) ?;
You can’t perform that action at this time.
0 commit comments