Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace all uses of pem with pem-rfc7468 crate #159

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading