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 @@ -177,6 +177,11 @@ impl Certificate {
177
177
Ok ( Certificate ( cert) )
178
178
}
179
179
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
+
180
185
pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
181
186
let der = self . 0 . to_der ( ) ?;
182
187
Ok ( der)
Original file line number Diff line number Diff line change @@ -167,6 +167,22 @@ impl Certificate {
167
167
panic ! ( "Not implemented on iOS" ) ;
168
168
}
169
169
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
+
170
186
pub fn to_der ( & self ) -> Result < Vec < u8 > , Error > {
171
187
Ok ( self . 0 . to_der ( ) )
172
188
}
Original file line number Diff line number Diff line change @@ -198,6 +198,12 @@ impl Certificate {
198
198
Ok ( Certificate ( cert) )
199
199
}
200
200
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
+
201
207
/// Returns the DER-encoded representation of this certificate.
202
208
pub fn to_der ( & self ) -> Result < Vec < u8 > > {
203
209
let der = self . 0 . to_der ( ) ?;
You can’t perform that action at this time.
0 commit comments