Skip to content

Commit 77a4965

Browse files
committed
Rename to cert-tools
1 parent 0779d8f commit 77a4965

5 files changed

Lines changed: 29 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/truststore-merger/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cert-tool"
2+
name = "cert-tools"
33
description = "A CLI tool to merge two truststores in PEM or PKCS12 format in such as way that they are accepted by the JVM"
44
version = "0.0.0-dev"
55
authors.workspace = true

rust/truststore-merger/src/cli_args.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ use crate::parsers::{parse_pem_contents, parse_pkcs12_file_workaround};
88

99
#[derive(Parser, Debug)]
1010
#[command(version, about)]
11-
pub struct Cli {
11+
pub enum Cli {
12+
/// Generate PKCS12 truststore files from PEM or PKCS12 files
13+
GeneratePkcs12Truststore(GeneratePkcs12),
14+
}
15+
16+
#[derive(Parser, Debug)]
17+
pub struct GeneratePkcs12 {
1218
/// The path to output the resulting PKCS12 to
1319
#[arg(long)]
1420
pub out: PathBuf,
@@ -54,7 +60,7 @@ fn parse_cli_pkcs12_source(cli_argument: &str) -> Result<Pkcs12Source, String> {
5460
})
5561
}
5662

57-
impl Cli {
63+
impl GeneratePkcs12 {
5864
pub fn certificate_sources(&self) -> Vec<CertInput> {
5965
let pems = self.pems.iter().cloned().map(CertInput::Pem);
6066
let pkcs12s = self.pkcs12s.iter().cloned().map(CertInput::Pkcs12);

rust/truststore-merger/src/main.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{collections::HashMap, fs};
33
use anyhow::{Context, ensure};
44
use cert_ext::CertExt;
55
use clap::Parser;
6-
use cli_args::Cli;
6+
use cli_args::{Cli, GeneratePkcs12};
77
use openssl::x509::X509;
88
use stackable_secret_operator_utils::pkcs12::pkcs12_truststore;
99
use tracing::{info, level_filters::LevelFilter, warn};
@@ -25,7 +25,15 @@ pub fn main() -> anyhow::Result<()> {
2525

2626
let cli = Cli::parse();
2727

28-
let certificate_sources = cli.certificate_sources();
28+
match cli {
29+
Cli::GeneratePkcs12Truststore(cli_args) => generate_pkcs12_truststore(cli_args)?,
30+
}
31+
32+
Ok(())
33+
}
34+
35+
fn generate_pkcs12_truststore(cli_args: GeneratePkcs12) -> anyhow::Result<()> {
36+
let certificate_sources = cli_args.certificate_sources();
2937
ensure!(
3038
!certificate_sources.is_empty(),
3139
"The list of certificate sources can not be empty. Please provide at least on --pem or --pkcs12."
@@ -79,12 +87,12 @@ pub fn main() -> anyhow::Result<()> {
7987
}
8088

8189
let pkcs12_truststore_bytes =
82-
pkcs12_truststore(certificates.values().map(|c| &**c), &cli.out_password)
90+
pkcs12_truststore(certificates.values().map(|c| &**c), &cli_args.out_password)
8391
.context("failed to create PKCS12 truststore from certificates")?;
84-
fs::write(&cli.out, &pkcs12_truststore_bytes).with_context(|| {
92+
fs::write(&cli_args.out, &pkcs12_truststore_bytes).with_context(|| {
8593
format!(
8694
"failed to write to output PKCS12 truststore at {:?}",
87-
cli.out
95+
cli_args.out
8896
)
8997
})?;
9098

0 commit comments

Comments
 (0)