@@ -5,6 +5,13 @@ use der::asn1::BitString;
55
66use crmf:: controls:: CertId ;
77use spki:: AlgorithmIdentifierOwned ;
8+ use x509_cert:: certificate:: { Profile , Rfc5280 } ;
9+
10+ #[ cfg( feature = "digest" ) ]
11+ use {
12+ der:: { asn1:: Null , oid:: AssociatedOid } ,
13+ x509_cert:: { certificate:: CertificateInner , ext:: pkix:: name:: GeneralName } ,
14+ } ;
815
916use crate :: header:: CmpCertificate ;
1017
@@ -31,7 +38,7 @@ pub type OobCert = CmpCertificate;
3138/// [RFC 4210 Section 5.2.5]: https://www.rfc-editor.org/rfc/rfc4210#section-5.2.5
3239#[ derive( Clone , Debug , Eq , PartialEq , Sequence ) ]
3340#[ allow( missing_docs) ]
34- pub struct OobCertHash {
41+ pub struct OobCertHash < P : Profile = Rfc5280 > {
3542 #[ asn1(
3643 context_specific = "0" ,
3744 tag_mode = "EXPLICIT" ,
@@ -45,6 +52,30 @@ pub struct OobCertHash {
4552 constructed = "true" ,
4653 optional = "true"
4754 ) ]
48- pub cert_id : Option < CertId > ,
55+ pub cert_id : Option < CertId < P > > ,
4956 pub hash_val : BitString ,
5057}
58+
59+ #[ cfg( feature = "digest" ) ]
60+ impl < P > OobCertHash < P >
61+ where
62+ P : Profile ,
63+ {
64+ /// Create an [`OobCertHash`] from a given certificate
65+ pub fn from_certificate < D > ( cert : & CertificateInner < P > ) -> der:: Result < Self >
66+ where
67+ D : digest:: Digest + AssociatedOid ,
68+ {
69+ Ok ( Self {
70+ hash_alg : Some ( AlgorithmIdentifierOwned {
71+ oid : D :: OID ,
72+ parameters : Some ( Null . into ( ) ) ,
73+ } ) ,
74+ cert_id : Some ( CertId {
75+ issuer : GeneralName :: DirectoryName ( cert. tbs_certificate ( ) . issuer ( ) . clone ( ) ) ,
76+ serial_number : cert. tbs_certificate ( ) . serial_number ( ) . clone ( ) ,
77+ } ) ,
78+ hash_val : BitString :: from_bytes ( & cert. hash :: < D > ( ) ?) ?,
79+ } )
80+ }
81+ }
0 commit comments