Skip to content

Commit d02368b

Browse files
committed
Update rcgen code
1 parent 48b70e4 commit d02368b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use metadata::{FileOptions, PresetMeta};
99
use {
1010
once_cell::sync::Lazy,
1111
percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS},
12-
rcgen::{Certificate, CertificateParams, DnType},
12+
rcgen::{CertificateParams, DnType, KeyPair},
1313
std::{
1414
borrow::Cow,
1515
error::Error,
@@ -298,20 +298,22 @@ fn args() -> Result<Args> {
298298
if !matches!(certs, Some(ref certs) if certs.has_domain(domain)) {
299299
log::info!("No certificate or key found for {:?}, generating them.", s);
300300

301-
let mut cert_params = CertificateParams::new(vec![domain.clone()]);
301+
let mut cert_params = CertificateParams::new(vec![domain.clone()])?;
302302
cert_params
303303
.distinguished_name
304304
.push(DnType::CommonName, domain);
305305

306306
// <CertificateParams as Default>::default() already implements a
307307
// date in the far future from the time of writing: 4096-01-01
308308

309-
if matches.opt_present("e") {
310-
cert_params.alg = &rcgen::PKCS_ED25519;
311-
}
309+
let key_pair = if matches.opt_present("e") {
310+
KeyPair::generate_for(&rcgen::PKCS_ED25519)
311+
} else {
312+
KeyPair::generate()
313+
}?;
312314

313315
// generate the certificate with the configuration
314-
let cert = Certificate::from_params(cert_params)?;
316+
let cert = cert_params.self_signed(&key_pair)?;
315317

316318
// make sure the certificate directory exists
317319
fs::create_dir(certs_path.join(domain))?;
@@ -321,7 +323,7 @@ fn args() -> Result<Args> {
321323
domain,
322324
certificates::CERT_FILE_NAME
323325
)))?;
324-
cert_file.write_all(&cert.serialize_der()?)?;
326+
cert_file.write_all(cert.der())?;
325327
// write key data to disk
326328
let key_file_path =
327329
certs_path.join(format!("{}/{}", domain, certificates::KEY_FILE_NAME));
@@ -337,7 +339,7 @@ fn args() -> Result<Args> {
337339
),
338340
}
339341
}
340-
key_file.write_all(&cert.serialize_private_key_der())?;
342+
key_file.write_all(key_pair.serialized_der())?;
341343

342344
reload_certs = true;
343345
}

0 commit comments

Comments
 (0)