Skip to content

Commit

Permalink
remove Attest::default() that panics if called twice (#1740)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Apr 11, 2024
1 parent a65ff21 commit 374517d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion task/attest/Cargo.toml
Expand Up @@ -8,13 +8,13 @@ arrayvec.workspace = true
lib-dice = { path = "../../lib/dice" }
hubpack = { workspace = true }
idol-runtime = { workspace = true }
mutable-statics = { path = "../../lib/mutable-statics" }
num-traits = { workspace = true }
ringbuf = { path = "../../lib/ringbuf" }
salty.workspace = true
serde = { workspace = true }
serde_with = { version = "3.3.0", default-features = false, features = ["macros"] }
stage0-handoff = { path = "../../lib/stage0-handoff" }
static-cell = { path = "../../lib/static-cell" }
attest-api = { path = "../attest-api" }
attest-data.workspace = true
sha3.workspace = true
Expand Down
24 changes: 15 additions & 9 deletions task/attest/src/main.rs
Expand Up @@ -89,11 +89,19 @@ struct AttestServer {
cert_data: Option<CertData>,
measurements: Log,
}

impl Default for AttestServer {
fn default() -> Self {
static LOG_BUF: ClaimOnceCell<[u8; Log::MAX_SIZE]> =
ClaimOnceCell::new([0; Log::MAX_SIZE]);
impl AttestServer {
/// Claims static resources and loads data.
//
/// # Panics
///
/// This function panics if called more than once.
fn claim_static_resources() -> Self {
let buf = {
use static_cell::ClaimOnceCell;
static LOG_BUF: ClaimOnceCell<[u8; Log::MAX_SIZE]> =
ClaimOnceCell::new([0; Log::MAX_SIZE]);
LOG_BUF.claim()
};

let alias_data: Option<AliasData> = load_data_from_region(&ALIAS_DATA);
let alias_keypair = alias_data
Expand All @@ -103,14 +111,12 @@ impl Default for AttestServer {
Self {
alias_data,
alias_keypair,
buf: LOG_BUF.claim(),
buf,
cert_data: load_data_from_region(&CERT_DATA),
measurements: Log::default(),
}
}
}

impl AttestServer {
fn get_cert_bytes_from_index(
&self,
index: u32,
Expand Down Expand Up @@ -396,7 +402,7 @@ fn main() -> ! {
ringbuf_entry!(Trace::Startup);

let mut buffer = [0; idl::INCOMING_SIZE];
let mut attest = AttestServer::default();
let mut attest = AttestServer::claim_static_resources();
loop {
idol_runtime::dispatch(&mut buffer, &mut attest);
}
Expand Down

0 comments on commit 374517d

Please sign in to comment.