@@ -197,7 +197,6 @@ impl Profile {
197
197
/// ```
198
198
/// use der::Decode;
199
199
/// use x509_cert::spki::SubjectPublicKeyInfoOwned;
200
- /// use x509_cert::certificate::Version;
201
200
/// use x509_cert::builder::{CertificateBuilder, Profile};
202
201
/// use x509_cert::name::Name;
203
202
/// use x509_cert::serial_number::SerialNumber;
@@ -226,7 +225,6 @@ impl Profile {
226
225
/// let mut signer = rsa_signer();
227
226
/// let mut builder = CertificateBuilder::new(
228
227
/// profile,
229
- /// Version::V3,
230
228
/// serial_number,
231
229
/// validity,
232
230
/// subject,
@@ -248,7 +246,6 @@ where
248
246
/// Creates a new certificate builder
249
247
pub fn new < Signature > (
250
248
profile : Profile ,
251
- version : Version ,
252
249
serial_number : SerialNumber ,
253
250
mut validity : Validity ,
254
251
subject : Name ,
@@ -270,7 +267,7 @@ where
270
267
validity. not_after . rfc5280_adjust_utc_time ( ) ?;
271
268
272
269
let mut tbs = TbsCertificate {
273
- version,
270
+ version : Version :: V3 ,
274
271
serial_number,
275
272
signature : signature_alg,
276
273
issuer,
@@ -288,15 +285,13 @@ where
288
285
subject_unique_id : None ,
289
286
} ;
290
287
291
- if tbs. version == Version :: V3 {
292
- let extensions = profile. build_extensions (
293
- tbs. subject_public_key_info . owned_to_ref ( ) ,
294
- signer_pub. owned_to_ref ( ) ,
295
- & tbs,
296
- ) ?;
297
- if !extensions. is_empty ( ) {
298
- tbs. extensions = Some ( extensions) ;
299
- }
288
+ let extensions = profile. build_extensions (
289
+ tbs. subject_public_key_info . owned_to_ref ( ) ,
290
+ signer_pub. owned_to_ref ( ) ,
291
+ & tbs,
292
+ ) ?;
293
+ if !extensions. is_empty ( ) {
294
+ tbs. extensions = Some ( extensions) ;
300
295
}
301
296
302
297
Ok ( Self { tbs, signer } )
@@ -319,11 +314,18 @@ where
319
314
}
320
315
321
316
/// Run the certificate through the signer and build the end certificate.
322
- pub fn build < Signature > ( self ) -> Result < Certificate >
317
+ pub fn build < Signature > ( mut self ) -> Result < Certificate >
323
318
where
324
319
S : Signer < Signature > ,
325
320
Signature : SignatureEncoding ,
326
321
{
322
+ if self . tbs . extensions . is_none ( ) {
323
+ if self . tbs . issuer_unique_id . is_some ( ) || self . tbs . subject_unique_id . is_some ( ) {
324
+ self . tbs . version = Version :: V2 ;
325
+ } else {
326
+ self . tbs . version = Version :: V1 ;
327
+ }
328
+ }
327
329
let signature = self . signer . try_sign ( & self . tbs . to_der ( ) ?) ?;
328
330
let signature = BitString :: from_bytes ( signature. to_bytes ( ) . as_ref ( ) ) ?;
329
331
0 commit comments