Skip to content

Commit e6bd761

Browse files
committed
Consistently spell KeyPair as two words
1 parent 66d9ff6 commit e6bd761

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

rustls-cert-gen/src/cert.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl PemCertifiedKey {
3434
#[derive(Default)]
3535
pub struct CertificateBuilder {
3636
params: CertificateParams,
37-
alg: KeypairAlgorithm,
37+
alg: KeyPairAlgorithm,
3838
}
3939

4040
impl CertificateBuilder {
@@ -50,11 +50,11 @@ impl CertificateBuilder {
5050
params.distinguished_name = DistinguishedName::new();
5151
Self {
5252
params,
53-
alg: KeypairAlgorithm::EcdsaP256,
53+
alg: KeyPairAlgorithm::EcdsaP256,
5454
}
5555
}
5656
/// Set signature algorithm (instead of default).
57-
pub fn signature_algorithm(mut self, alg: KeypairAlgorithm) -> anyhow::Result<Self> {
57+
pub fn signature_algorithm(mut self, alg: KeyPairAlgorithm) -> anyhow::Result<Self> {
5858
self.alg = alg;
5959
Ok(self)
6060
}
@@ -76,12 +76,12 @@ impl CertificateBuilder {
7676
/// [CertificateParams] from which an [Ca] [Certificate] can be built
7777
pub struct CaBuilder {
7878
params: CertificateParams,
79-
alg: KeypairAlgorithm,
79+
alg: KeyPairAlgorithm,
8080
}
8181

8282
impl CaBuilder {
8383
/// Initialize `CaBuilder`
84-
pub fn new(mut params: CertificateParams, alg: KeypairAlgorithm) -> Self {
84+
pub fn new(mut params: CertificateParams, alg: KeyPairAlgorithm) -> Self {
8585
params.is_ca = IsCa::Ca(BasicConstraints::Unconstrained);
8686
params.key_usages.push(KeyUsagePurpose::DigitalSignature);
8787
params.key_usages.push(KeyUsagePurpose::KeyCertSign);
@@ -106,7 +106,7 @@ impl CaBuilder {
106106
}
107107
/// build `Ca` Certificate.
108108
pub fn build(self) -> Result<Ca, rcgen::Error> {
109-
let key_pair = self.alg.to_keypair()?;
109+
let key_pair = self.alg.to_key_pair()?;
110110
let cert = Certificate::generate_self_signed(self.params, &key_pair)?;
111111
Ok(Ca { cert, key_pair })
112112
}
@@ -152,12 +152,12 @@ impl EndEntity {
152152
/// [CertificateParams] from which an [EndEntity] [Certificate] can be built
153153
pub struct EndEntityBuilder {
154154
params: CertificateParams,
155-
alg: KeypairAlgorithm,
155+
alg: KeyPairAlgorithm,
156156
}
157157

158158
impl EndEntityBuilder {
159159
/// Initialize `EndEntityBuilder`
160-
pub fn new(mut params: CertificateParams, alg: KeypairAlgorithm) -> Self {
160+
pub fn new(mut params: CertificateParams, alg: KeyPairAlgorithm) -> Self {
161161
params.is_ca = IsCa::NoCa;
162162
params.use_authority_key_identifier_extension = true;
163163
params.key_usages.push(KeyUsagePurpose::DigitalSignature);
@@ -196,36 +196,36 @@ impl EndEntityBuilder {
196196
}
197197
/// build `EndEntity` Certificate.
198198
pub fn build(self, issuer: &Ca) -> Result<EndEntity, rcgen::Error> {
199-
let key_pair = self.alg.to_keypair()?;
199+
let key_pair = self.alg.to_key_pair()?;
200200
let cert = Certificate::generate(self.params, &issuer.cert, &key_pair, &issuer.key_pair)?;
201201
Ok(EndEntity { cert, key_pair })
202202
}
203203
}
204204

205205
/// Supported Keypair Algorithms
206206
#[derive(Clone, Copy, Debug, Default, Bpaf, PartialEq)]
207-
pub enum KeypairAlgorithm {
207+
pub enum KeyPairAlgorithm {
208208
Ed25519,
209209
#[default]
210210
EcdsaP256,
211211
EcdsaP384,
212212
}
213213

214-
impl fmt::Display for KeypairAlgorithm {
214+
impl fmt::Display for KeyPairAlgorithm {
215215
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
216216
match self {
217-
KeypairAlgorithm::Ed25519 => write!(f, "ed25519"),
218-
KeypairAlgorithm::EcdsaP256 => write!(f, "ecdsa-p256"),
219-
KeypairAlgorithm::EcdsaP384 => write!(f, "ecdsa-p384"),
217+
KeyPairAlgorithm::Ed25519 => write!(f, "ed25519"),
218+
KeyPairAlgorithm::EcdsaP256 => write!(f, "ecdsa-p256"),
219+
KeyPairAlgorithm::EcdsaP384 => write!(f, "ecdsa-p384"),
220220
}
221221
}
222222
}
223223

224-
impl KeypairAlgorithm {
224+
impl KeyPairAlgorithm {
225225
/// Return an `rcgen::KeyPair` for the given varient
226-
fn to_keypair(&self) -> Result<rcgen::KeyPair, rcgen::Error> {
226+
fn to_key_pair(&self) -> Result<rcgen::KeyPair, rcgen::Error> {
227227
match self {
228-
KeypairAlgorithm::Ed25519 => {
228+
KeyPairAlgorithm::Ed25519 => {
229229
use ring::signature::Ed25519KeyPair;
230230

231231
let rng = ring::rand::SystemRandom::new();
@@ -235,7 +235,7 @@ impl KeypairAlgorithm {
235235

236236
rcgen::KeyPair::from_der_and_sign_algo(pkcs8_bytes.as_ref(), alg)
237237
},
238-
KeypairAlgorithm::EcdsaP256 => {
238+
KeyPairAlgorithm::EcdsaP256 => {
239239
use ring::signature::EcdsaKeyPair;
240240
use ring::signature::ECDSA_P256_SHA256_ASN1_SIGNING;
241241

@@ -246,7 +246,7 @@ impl KeypairAlgorithm {
246246
.or(Err(rcgen::Error::RingUnspecified))?;
247247
rcgen::KeyPair::from_der_and_sign_algo(pkcs8_bytes.as_ref(), alg)
248248
},
249-
KeypairAlgorithm::EcdsaP384 => {
249+
KeyPairAlgorithm::EcdsaP384 => {
250250
use ring::signature::EcdsaKeyPair;
251251
use ring::signature::ECDSA_P384_SHA384_ASN1_SIGNING;
252252

@@ -298,7 +298,7 @@ mod tests {
298298
fn with_sig_algo_default() -> anyhow::Result<()> {
299299
let end_entity = CertificateBuilder::new().end_entity();
300300

301-
assert_eq!(end_entity.alg, KeypairAlgorithm::EcdsaP256);
301+
assert_eq!(end_entity.alg, KeyPairAlgorithm::EcdsaP256);
302302
Ok(())
303303
}
304304
#[test]
@@ -324,7 +324,7 @@ mod tests {
324324
fn serialize_end_entity_ecdsa_p384_sha384_sig() -> anyhow::Result<()> {
325325
let ca = CertificateBuilder::new().certificate_authority().build()?;
326326
let end_entity = CertificateBuilder::new()
327-
.signature_algorithm(KeypairAlgorithm::EcdsaP384)?
327+
.signature_algorithm(KeyPairAlgorithm::EcdsaP384)?
328328
.end_entity()
329329
.build(&ca)?
330330
.serialize_pem();
@@ -343,7 +343,7 @@ mod tests {
343343
fn serialize_end_entity_ed25519_sig() -> anyhow::Result<()> {
344344
let ca = CertificateBuilder::new().certificate_authority().build()?;
345345
let end_entity = CertificateBuilder::new()
346-
.signature_algorithm(KeypairAlgorithm::Ed25519)?
346+
.signature_algorithm(KeyPairAlgorithm::Ed25519)?
347347
.end_entity()
348348
.build(&ca)?
349349
.serialize_pem();
@@ -365,7 +365,7 @@ mod tests {
365365
#[test]
366366
fn init_end_endity() {
367367
let params = CertificateParams::default();
368-
let cert = EndEntityBuilder::new(params, KeypairAlgorithm::default());
368+
let cert = EndEntityBuilder::new(params, KeyPairAlgorithm::default());
369369
assert_eq!(cert.params.is_ca, IsCa::NoCa)
370370
}
371371
#[test]
@@ -375,7 +375,7 @@ mod tests {
375375
.build()
376376
.unwrap();
377377
let params = CertificateParams::default();
378-
let mut cert = EndEntityBuilder::new(params, KeypairAlgorithm::default());
378+
let mut cert = EndEntityBuilder::new(params, KeyPairAlgorithm::default());
379379
assert_eq!(cert.params.is_ca, IsCa::NoCa);
380380
assert_eq!(
381381
cert.client_auth().params.extended_key_usages,
@@ -389,7 +389,7 @@ mod tests {
389389
.build()
390390
.unwrap();
391391
let params = CertificateParams::default();
392-
let mut cert = EndEntityBuilder::new(params, KeypairAlgorithm::default());
392+
let mut cert = EndEntityBuilder::new(params, KeyPairAlgorithm::default());
393393
assert_eq!(cert.params.is_ca, IsCa::NoCa);
394394
assert_eq!(
395395
cert.server_auth().params.extended_key_usages,
@@ -405,7 +405,7 @@ mod tests {
405405
let name = "unexpected.oomyoo.xyz";
406406
let names = vec![SanType::DnsName(name.into())];
407407
let params = CertificateParams::default();
408-
let cert = EndEntityBuilder::new(params, KeypairAlgorithm::default())
408+
let cert = EndEntityBuilder::new(params, KeyPairAlgorithm::default())
409409
.subject_alternative_names(names);
410410
assert_eq!(
411411
cert.params.subject_alt_names,
@@ -420,21 +420,21 @@ mod tests {
420420
.unwrap();
421421
let names = vec![];
422422
let params = CertificateParams::default();
423-
let cert = EndEntityBuilder::new(params, KeypairAlgorithm::default())
423+
let cert = EndEntityBuilder::new(params, KeyPairAlgorithm::default())
424424
.subject_alternative_names(names);
425425
assert_eq!(cert.params.subject_alt_names, vec![]);
426426
}
427427

428428
#[test]
429-
fn keypair_algorithm_to_keypair() -> anyhow::Result<()> {
430-
let keypair = KeypairAlgorithm::Ed25519.to_keypair()?;
429+
fn key_pair_algorithm_to_keypair() -> anyhow::Result<()> {
430+
let keypair = KeyPairAlgorithm::Ed25519.to_key_pair()?;
431431
assert_eq!(format!("{:?}", keypair.algorithm()), "PKCS_ED25519");
432-
let keypair = KeypairAlgorithm::EcdsaP256.to_keypair()?;
432+
let keypair = KeyPairAlgorithm::EcdsaP256.to_key_pair()?;
433433
assert_eq!(
434434
format!("{:?}", keypair.algorithm()),
435435
"PKCS_ECDSA_P256_SHA256"
436436
);
437-
let keypair = KeypairAlgorithm::EcdsaP384.to_keypair()?;
437+
let keypair = KeyPairAlgorithm::EcdsaP384.to_key_pair()?;
438438
assert_eq!(
439439
format!("{:?}", keypair.algorithm()),
440440
"PKCS_ECDSA_P384_SHA384"

rustls-cert-gen/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rcgen::SanType;
33
use std::{net::IpAddr, path::PathBuf};
44

55
mod cert;
6-
use cert::{keypair_algorithm, CertificateBuilder, KeypairAlgorithm};
6+
use cert::{key_pair_algorithm, CertificateBuilder, KeyPairAlgorithm};
77

88
fn main() -> anyhow::Result<()> {
99
let opts = options().run();
@@ -48,12 +48,12 @@ struct Options {
4848
pub output: PathBuf,
4949
/// Keypair algorithm
5050
#[bpaf(
51-
external(keypair_algorithm),
52-
fallback(KeypairAlgorithm::EcdsaP256),
51+
external(key_pair_algorithm),
52+
fallback(KeyPairAlgorithm::EcdsaP256),
5353
display_fallback,
5454
group_help("Keypair Algorithm:")
5555
)]
56-
pub keypair_algorithm: KeypairAlgorithm,
56+
pub keypair_algorithm: KeyPairAlgorithm,
5757
/// Extended Key Usage Purpose: ClientAuth
5858
#[bpaf(long)]
5959
pub client_auth: bool,

0 commit comments

Comments
 (0)