Skip to content

Commit

Permalink
Shorten expire CLI arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarzik committed Feb 20, 2024
1 parent bccc978 commit 2a6e574
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Options:
Server cert: city or locality
--srv-org <SRV_ORG>
Server cert: organization
--srv-expire-days <SRV_EXPIRE_DAYS>
--srv-expire <SRV_EXPIRE>
Server cert: days until expiration [default: 365]
--ca-common-name <CA_COMMON_NAME>
Expand All @@ -63,7 +63,7 @@ Options:
CA cert: city or locality
--ca-org <CA_ORG>
CA cert: organization
--ca-expire-days <CA_EXPIRE_DAYS>
--ca-expire <CA_EXPIRE>
CA cert: days until expiration [default: 365]
--common-name <COMMON_NAME>
Expand All @@ -76,7 +76,7 @@ Options:
city or locality: Default set for both CA and server certs
--org <ORG>
organization: Default set for both CA and server certs
--expire-days <EXPIRE_DAYS>
--expire <EXPIRE>
expire days: Default set for both CA and server certs
-h, --help
Expand Down
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct Args {

/// Server cert: days until expiration
#[arg(long, default_value_t = 365)]
srv_expire_days: u32,
srv_expire: u32,

/// CA cert: common name
#[arg(long, default_value = "127.0.0.1")]
Expand All @@ -99,7 +99,7 @@ struct Args {

/// CA cert: days until expiration
#[arg(long, default_value_t = 365)]
ca_expire_days: u32,
ca_expire: u32,

/// common name: Default set for both CA and server certs.
#[arg(long)]
Expand All @@ -123,7 +123,7 @@ struct Args {

/// expire days: Default set for both CA and server certs.
#[arg(long)]
expire_days: Option<u32>,
expire: Option<u32>,
}

/// Process CLI args that assign two settings simultaneously
Expand Down Expand Up @@ -163,10 +163,10 @@ fn swizzle_args(args: &mut Args) {
}
None => {}
}
match &args.expire_days {
match &args.expire {
Some(val) => {
args.ca_expire_days = *val;
args.srv_expire_days = *val;
args.ca_expire = *val;
args.srv_expire = *val;
}
None => {}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ fn create_root_ca_certificate(args: &Args, pkey: &PKey<Private>) -> Result<X509,
builder.set_pubkey(pkey)?;

let not_before = Asn1Time::days_from_now(0)?;
let not_after = Asn1Time::days_from_now(args.ca_expire_days)?;
let not_after = Asn1Time::days_from_now(args.ca_expire)?;
builder.set_not_before(&not_before)?;
builder.set_not_after(&not_after)?;

Expand Down Expand Up @@ -303,7 +303,7 @@ fn sign_server_csr(

// Set validity
let not_before = openssl::asn1::Asn1Time::days_from_now(0)?;
let not_after = openssl::asn1::Asn1Time::days_from_now(args.srv_expire_days)?;
let not_after = openssl::asn1::Asn1Time::days_from_now(args.srv_expire)?;
builder.set_not_before(&not_before)?;
builder.set_not_after(&not_after)?;

Expand Down

0 comments on commit 2a6e574

Please sign in to comment.