@@ -10,17 +10,15 @@ use rustls::crypto::ring::cipher_suite::TLS13_CHACHA20_POLY1305_SHA256;
1010use rustls:: crypto:: ring:: kx_group:: X25519 ;
1111use rustls:: crypto:: CryptoProvider ;
1212use slog:: error;
13- use std:: io:: prelude:: * ;
1413use std:: io:: IoSlice ;
1514use std:: marker:: Unpin ;
1615
1716#[ cfg( any( unix, target_os = "wasi" ) ) ]
1817use std:: os:: fd:: { AsRawFd , RawFd } ;
1918
20- use anyhow:: Context ;
21- use std:: fs:: File ;
2219use std:: pin:: Pin ;
2320use std:: task:: { self , Poll } ;
21+ use std:: { fs, io} ;
2422use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt , ReadBuf } ;
2523use tokio_rustls:: TlsStream ;
2624use 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
222223pub 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
234233fn certs_to_der ( certs : & [ Certificate ] ) -> Result < Vec < u8 > , Error > {
0 commit comments