File tree Expand file tree Collapse file tree 4 files changed +23
-5
lines changed
Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,9 @@ pub use {
8989 } ,
9090} ;
9191
92+ #[ cfg( feature = "alloc" ) ]
93+ pub use trust_anchor:: spki_for_anchor;
94+
9295#[ cfg( feature = "alloc" ) ]
9396pub use crl:: { OwnedCertRevocationList , OwnedRevokedCert } ;
9497
Original file line number Diff line number Diff line change 1- use pki_types:: { CertificateDer , TrustAnchor } ;
1+ use pki_types:: { CertificateDer , SubjectPublicKeyInfoDer , TrustAnchor } ;
22
33use crate :: cert:: { Cert , lenient_certificate_serial_number} ;
44use crate :: der;
@@ -43,6 +43,12 @@ pub fn anchor_from_trusted_cert<'a>(
4343 }
4444}
4545
46+ /// Reconstitutes the given trust anchor's SubjectPublicKeyInfo.
47+ #[ cfg( feature = "alloc" ) ]
48+ pub fn spki_for_anchor ( anchor : & TrustAnchor < ' _ > ) -> SubjectPublicKeyInfoDer < ' static > {
49+ der:: asn1_wrap ( der:: Tag :: Sequence , & anchor. subject_public_key_info ) . into ( )
50+ }
51+
4652/// Parses a v1 certificate directly into a TrustAnchor.
4753fn extract_trust_anchor_from_v1_cert_der (
4854 cert_der : untrusted:: Input < ' _ > ,
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ use crate::crl::RevocationOptions;
2626use crate :: der:: { self , FromDer } ;
2727use crate :: end_entity:: EndEntityCert ;
2828use crate :: error:: Error ;
29+ #[ cfg( feature = "alloc" ) ]
30+ use crate :: trust_anchor;
2931use crate :: { public_values_eq, subject_name} ;
3032
3133// Use `'a` for lifetimes that we don't care about, `'p` for lifetimes that become a part of
@@ -220,10 +222,7 @@ impl<'p> VerifiedPath<'p> {
220222 pub fn issuer_spki ( & self ) -> SubjectPublicKeyInfoDer < ' p > {
221223 match self . intermediate_certificates ( ) . next ( ) {
222224 Some ( issuer) => issuer. subject_public_key_info ( ) ,
223- None => SubjectPublicKeyInfoDer :: from ( der:: asn1_wrap (
224- der:: Tag :: Sequence ,
225- self . anchor . subject_public_key_info . as_ref ( ) ,
226- ) ) ,
225+ None => trust_anchor:: spki_for_anchor ( self . anchor ) ,
227226 }
228227 }
229228}
Original file line number Diff line number Diff line change @@ -509,3 +509,13 @@ fn no_scts() {
509509 cert. sct_log_timestamps( ) . collect:: <Result <Vec <_>, _>>( )
510510 ) ;
511511}
512+
513+ #[ cfg( feature = "alloc" ) ]
514+ #[ test]
515+ fn anchor_spki ( ) {
516+ let ca = CertificateDer :: from ( & include_bytes ! ( "netflix/ca.der" ) [ ..] ) ;
517+ let anchor = anchor_from_trusted_cert ( & ca) . unwrap ( ) ;
518+ let spki = webpki:: spki_for_anchor ( & anchor) ;
519+
520+ assert_eq ! ( Some ( & 0x30 ) , spki. first( ) ) ; // starts with SEQUENCE
521+ }
You can’t perform that action at this time.
0 commit comments