Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #102 from registreerocks/he-sgxfs-kv-fix
Browse files Browse the repository at this point in the history
fix(tenclave): use sgxfs read for correct not-found error handling
  • Loading branch information
longtomjr authored Jun 17, 2021
2 parents b2f083b + e18c2d0 commit 233ce7a
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions rtc_tenclave/src/kv_store/fs/sgx_filer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::prelude::v1::Vec;

use std::io::ErrorKind::NotFound;
use std::io::Read;
use std::io::Result;
use std::io::Write;
use std::path::Path;
Expand All @@ -23,9 +22,8 @@ pub struct SgxFiler;
//
impl Filer for SgxFiler {
fn get(&self, path: impl AsRef<Path>) -> Result<Option<Vec<u8>>> {
// TODO: open_ex with key
let value_file = SgxFile::open(path)?;
match read_all(value_file) {
// TODO: Create `read_ex` to read file with key
match sgxfs::read(path) {
Ok(contents) => Ok(Some(contents)),
Err(error) if error.kind() == NotFound => Ok(None),
Err(error) => Err(error),
Expand All @@ -46,11 +44,3 @@ impl Filer for SgxFiler {
}
}
}

/// Helper: Like [`fs::read`], but take an open file.
fn read_all(mut file: SgxFile) -> Result<Vec<u8>> {
// XXX: No metadata for initial_buffer_size in sgxfs
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
Ok(buf)
}

0 comments on commit 233ce7a

Please sign in to comment.