From 8f3114826dd0f7148732d2d324c737009cf60652 Mon Sep 17 00:00:00 2001 From: ryardley Date: Mon, 26 Aug 2024 11:38:21 +1000 Subject: [PATCH] Add binary encoding --- packages/ciphernode/Cargo.lock | 10 ++++++++++ packages/ciphernode/core/Cargo.toml | 1 + packages/ciphernode/core/src/events.rs | 13 ++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/ciphernode/Cargo.lock b/packages/ciphernode/Cargo.lock index ff60f23a..7d8ff2d1 100644 --- a/packages/ciphernode/Cargo.lock +++ b/packages/ciphernode/Cargo.lock @@ -530,6 +530,15 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "230c5f1ca6a325a32553f8640d31ac9b49f2411e901e427570154868b46da4f7" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -901,6 +910,7 @@ dependencies = [ "actix-rt", "anyhow", "async-std", + "bincode", "bs58", "fhe", "fhe-traits", diff --git a/packages/ciphernode/core/Cargo.toml b/packages/ciphernode/core/Cargo.toml index 8cc627e7..44544994 100644 --- a/packages/ciphernode/core/Cargo.toml +++ b/packages/ciphernode/core/Cargo.toml @@ -25,4 +25,5 @@ tokio = { version = "1.39.3", features = ["full"] } sha2 = "0.10.8" bs58 = "0.5.1" serde = { version = "1.0.208", features = ["derive"] } +bincode = "1.3.3" diff --git a/packages/ciphernode/core/src/events.rs b/packages/ciphernode/core/src/events.rs index 1fe46f59..b638db4d 100644 --- a/packages/ciphernode/core/src/events.rs +++ b/packages/ciphernode/core/src/events.rs @@ -1,4 +1,5 @@ use actix::Message; +use bincode; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::{ @@ -64,6 +65,16 @@ pub enum EnclaveEvent { // CiphernodeDeregistered, } +impl EnclaveEvent { + pub fn to_bytes(&self) -> Result, bincode::Error> { + bincode::serialize(self) + } + + pub fn from_bytes(bytes: &[u8]) -> Result { + bincode::deserialize(bytes) + } +} + impl From for EventId { fn from(value: EnclaveEvent) -> Self { match value { @@ -115,7 +126,7 @@ pub struct PublicKeyAggregated { pub e3_id: E3id, } -#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize,Deserialize)] +#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[rtype(result = "()")] pub struct ComputationRequested { pub e3_id: E3id,