Skip to content

Commit 6b87cc4

Browse files
committed
Remove anyhow from the library API & simplify load_root_cert
1 parent 7b63ccb commit 6b87cc4

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

tls/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = "2021"
55

66
[dependencies]
77
clap.workspace = true
8-
anyhow.workspace = true
98
attest-data.workspace = true
109
camino.workspace = true
1110
cfg-if.workspace = true

tls/src/lib.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ use rustls::crypto::ring::cipher_suite::TLS13_CHACHA20_POLY1305_SHA256;
1010
use rustls::crypto::ring::kx_group::X25519;
1111
use rustls::crypto::CryptoProvider;
1212
use slog::error;
13-
use std::io::prelude::*;
1413
use std::io::IoSlice;
1514
use std::marker::Unpin;
1615

1716
#[cfg(any(unix, target_os = "wasi"))]
1817
use std::os::fd::{AsRawFd, RawFd};
1918

20-
use anyhow::Context;
21-
use std::fs::File;
2219
use std::pin::Pin;
2320
use std::task::{self, Poll};
21+
use std::{fs, io};
2422
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf};
2523
use tokio_rustls::TlsStream;
2624
use x509_cert::{
@@ -51,9 +49,12 @@ pub enum Error {
5149
#[error("io error: {0}")]
5250
Io(#[from] std::io::Error),
5351

54-
// TODO: Return a more specific error / errors from dice-util
55-
#[error("dice error: {0}")]
56-
Dice(#[from] anyhow::Error),
52+
#[error("io error: {path}")]
53+
FailedRead {
54+
path: Utf8PathBuf,
55+
#[source]
56+
err: io::Error,
57+
},
5758

5859
#[error("RotRequest: {0}")]
5960
RotRequest(#[from] ipcc::RotRequestError),
@@ -220,15 +221,13 @@ where
220221
}
221222

222223
pub fn load_root_cert(path: &Utf8PathBuf) -> Result<Certificate, Error> {
223-
let mut root_cert_pem = Vec::new();
224-
File::open(path)
225-
.with_context(|| format!("failed to open {}", &path))?
226-
.read_to_end(&mut root_cert_pem)
227-
.with_context(|| format!("failed to read {}", &path))?;
228-
let root = Certificate::from_pem(&root_cert_pem).with_context(|| {
229-
format!("failed to convert pem read from {}", &path)
224+
let cert = fs::read(path).map_err(|err| Error::FailedRead {
225+
path: path.to_owned(),
226+
err,
230227
})?;
231-
Ok(root)
228+
let cert = Certificate::from_pem(&cert)?;
229+
230+
Ok(cert)
232231
}
233232

234233
fn certs_to_der(certs: &[Certificate]) -> Result<Vec<u8>, Error> {

0 commit comments

Comments
 (0)