Skip to content

Commit

Permalink
dice-mfg: replace pem crate w/ pem-rfc7468
Browse files Browse the repository at this point in the history
  • Loading branch information
flihp committed Feb 14, 2024
1 parent 21c40a5 commit 306738f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
20 changes: 2 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ hex.version = "0.4"
hubpack = "0.1"
log = { version = "0.4", features = ["std"] }
p384 = { version = "0.13", default-features = false }
pem = { version = "3", default-features = false }
pem-rfc7468 = { version = "0.7.0", default-features = false }
ron = "0.8"
rpassword = "7.3.1"
Expand Down
2 changes: 1 addition & 1 deletion dice-mfg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ corncobs.workspace = true
dice-mfg-msgs = { path = "../dice-mfg-msgs", features = ["std"] }
env_logger.workspace = true
log.workspace = true
pem = { workspace = true, features = ["std"] }
pem-rfc7468 = { workspace = true, features = ["alloc", "std"] }
rpassword.workspace = true
serde_json.workspace = true
serialport.workspace = true
Expand Down
21 changes: 8 additions & 13 deletions dice-mfg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,25 +619,20 @@ impl CertSigner {
}

fn sized_blob_from_pem_path(p: &PathBuf) -> Result<SizedBlob> {
let cert = fs::read_to_string(p)?;
let cert = pem::parse(cert)?;
let cert = fs::read(p)?;
let (_, cert) = pem_rfc7468::decode_vec(&cert)?;

// Error type doesn't implement std Error
Ok(SizedBlob::try_from(cert.contents())?)
Ok(SizedBlob::try_from(&cert[..])?)
}

pub fn save_csr<W: Write>(mut w: W, csr: SizedBlob) -> Result<()> {
let size = usize::from(csr.size);

// encode as PEM
let pem = pem::Pem::new(
String::from("CERTIFICATE REQUEST"),
csr.as_bytes()[..size].to_vec(),
);
let csr_pem = pem::encode_config(
&pem,
pem::EncodeConfig::new().set_line_ending(pem::LineEnding::LF),
);
let csr_pem = pem_rfc7468::encode_string(
"CERTIFICATE REQUEST",
pem_rfc7468::LineEnding::LF,
&csr.as_bytes()[..size],
)?;

Ok(w.write_all(csr_pem.as_bytes())?)
}
Expand Down

0 comments on commit 306738f

Please sign in to comment.