oasis_core_runtime/enclave_rpc/
types.rs1use rand::{rngs::OsRng, Rng};
3
4impl_bytes!(
5 SessionID,
6 32,
7 "Session identifier for multiplexing multiple sessions over the \
8 same transport"
9);
10
11impl SessionID {
12 pub fn random() -> Self {
14 let mut session_id = [0u8; 32];
15 OsRng.fill(&mut session_id);
16
17 SessionID(session_id)
18 }
19}
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, cbor::Encode, cbor::Decode)]
23#[cbor(with_default)]
24#[repr(u8)]
25pub enum Kind {
26 NoiseSession = 0,
28 InsecureQuery = 1,
30 LocalQuery = 2,
32}
33
34impl Default for Kind {
35 fn default() -> Self {
36 Self::NoiseSession
37 }
38}
39
40#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
42pub struct Frame {
43 pub session: SessionID,
44 pub untrusted_plaintext: String,
50 pub payload: Vec<u8>,
51}
52
53#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
54#[cbor(no_default)]
55pub struct Request {
56 pub method: String,
57 pub args: cbor::Value,
58}
59
60#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
61pub struct Error {
62 pub message: String,
63}
64
65#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
66pub enum Body {
67 Success(cbor::Value),
68 Error(String),
69}
70
71#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
72#[cbor(no_default)]
73pub struct Response {
74 pub body: Body,
75}
76
77#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
79pub enum Message {
80 Request(Request),
81 Response(Response),
82 Close,
83}
84
85#[derive(Copy, Clone, Debug, PartialEq, Eq, cbor::Encode, cbor::Decode)]
87pub enum PeerFeedback {
88 Success = 0,
89 Failure = 1,
90 BadPeer = 2,
91}