-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathengine.rs
More file actions
37 lines (29 loc) · 1.09 KB
/
engine.rs
File metadata and controls
37 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::ecalls::EnclaveConnector;
use codec::{Decode, Encode};
use frame_common::{EcallInput, EcallOutput};
use sgx_types::sgx_enclave_id_t;
pub trait HostEngine {
type HI: HostInput<EcallInput = Self::EI, HostOutput = Self::HO>;
type EI: EcallInput + Encode;
type EO: EcallOutput + Decode;
type HO: HostOutput<EcallOutput = Self::EO>;
const OUTPUT_MAX_LEN: usize;
const CMD: u32;
fn exec(input: Self::HI, eid: sgx_enclave_id_t) -> anyhow::Result<Self::HO> {
let (ecall_input, host_output) = input.apply()?;
let ecall_output = EnclaveConnector::new(eid, Self::OUTPUT_MAX_LEN)
.invoke_ecall::<Self::EI, Self::EO>(Self::CMD, ecall_input)?;
host_output.set_ecall_output(ecall_output)
}
}
pub trait HostInput: Sized {
type EcallInput: EcallInput;
type HostOutput: HostOutput;
fn apply(self) -> anyhow::Result<(Self::EcallInput, Self::HostOutput)>;
}
pub trait HostOutput: Sized {
type EcallOutput: EcallOutput;
fn set_ecall_output(self, _output: Self::EcallOutput) -> anyhow::Result<Self> {
Ok(self)
}
}