@@ -41,7 +41,8 @@ use std::net::IpAddr;
41
41
use std:: net:: { Ipv4Addr , Ipv6Addr } ;
42
42
use std:: ops:: Deref ;
43
43
44
- #[ cfg( feature = "x509-parser" ) ]
44
+ #[ cfg( feature = "pem" ) ]
45
+ use pem:: Pem ;
45
46
use pki_types:: CertificateDer ;
46
47
use time:: { OffsetDateTime , Time } ;
47
48
use yasna:: models:: ObjectIdentifier ;
@@ -136,6 +137,55 @@ pub fn generate_simple_self_signed(
136
137
Ok ( CertifiedKey { cert, signing_key } )
137
138
}
138
139
140
+ /// An [`Issuer`] wrapper that also contains the issuer's [`Certificate`].
141
+ pub struct CertifiedIssuer < ' a , S > {
142
+ certificate : Certificate ,
143
+ issuer : Issuer < ' a , S > ,
144
+ }
145
+
146
+ impl < ' a , S : SigningKey > CertifiedIssuer < ' a , S > {
147
+ /// Create a new issuer from the given parameters and key, with a self-signed certificate.
148
+ pub fn self_signed ( params : CertificateParams , signing_key : S ) -> Result < Self , Error > {
149
+ Ok ( Self {
150
+ certificate : params. self_signed ( & signing_key) ?,
151
+ issuer : Issuer :: new ( params, signing_key) ,
152
+ } )
153
+ }
154
+
155
+ /// Create a new issuer from the given parameters and key, signed by the given `issuer`.
156
+ pub fn signed_by (
157
+ params : CertificateParams ,
158
+ signing_key : S ,
159
+ issuer : & Issuer < ' _ , impl SigningKey > ,
160
+ ) -> Result < Self , Error > {
161
+ Ok ( Self {
162
+ certificate : params. signed_by ( & signing_key, issuer) ?,
163
+ issuer : Issuer :: new ( params, signing_key) ,
164
+ } )
165
+ }
166
+
167
+ /// Get the certificate in PEM encoded format.
168
+ #[ cfg( feature = "pem" ) ]
169
+ pub fn pem ( & self ) -> String {
170
+ pem:: encode_config ( & Pem :: new ( "CERTIFICATE" , self . der ( ) . to_vec ( ) ) , ENCODE_CONFIG )
171
+ }
172
+
173
+ /// Get the certificate in DER encoded format.
174
+ ///
175
+ /// See also [`Certificate::der()`]
176
+ pub fn der ( & self ) -> & CertificateDer < ' static > {
177
+ self . certificate . der ( )
178
+ }
179
+ }
180
+
181
+ impl < ' a , S > Deref for CertifiedIssuer < ' a , S > {
182
+ type Target = Issuer < ' a , S > ;
183
+
184
+ fn deref ( & self ) -> & Self :: Target {
185
+ & self . issuer
186
+ }
187
+ }
188
+
139
189
/// An issuer that can sign certificates.
140
190
///
141
191
/// Encapsulates the distinguished name, key identifier method, key usages and signing key
0 commit comments