Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

Commit

Permalink
Remove manual serde Serialize/Deserialize implementation (#159)
Browse files Browse the repository at this point in the history
Remove manual serde Serialize/Deserialize implementation
  • Loading branch information
elichai authored May 22, 2019
2 parents 0ac7669 + e94ddd3 commit b24c4f6
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 284 deletions.
2 changes: 2 additions & 0 deletions eng-wasm/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![feature(box_patterns)]
#![recursion_limit="128"]
#![feature(slice_concat_ext)]
#![allow(unused_attributes)] // TODO: Remove on future nightly https://github.com/rust-lang/rust/issues/60050


extern crate eng_wasm;
extern crate proc_macro2;
Expand Down
2 changes: 2 additions & 0 deletions eng-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![no_std]
#![feature(slice_concat_ext)]
#![deny(unused_extern_crates)]
#![allow(unused_attributes)] // TODO: Remove on future nightly https://github.com/rust-lang/rust/issues/60050


/// Enigma implementation of bindings to the Enigma runtime.
/// This crate should be used in contracts.
Expand Down
4 changes: 3 additions & 1 deletion enigma-core/enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#![crate_type = "staticlib"]
#![no_std]
#![cfg_attr(target_env = "sgx", feature(rustc_private))]

#![warn(clippy::all)]
#![allow(clippy::cast_ptr_alignment)] // TODO: Try to remove it when fixing the sealing
#![warn(unused_extern_crates)]
#![allow(clippy::cast_ptr_alignment)] // TODO: Try to remove it when fixing the sealing
#![allow(unused_attributes)] // TODO: Remove on future nightly https://github.com/rust-lang/rust/issues/60050

extern crate enigma_runtime_t;
#[macro_use]
Expand Down
1 change: 1 addition & 0 deletions enigma-crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use enigma_types::Hash256;
/// let ready = hash::prepare_hash_multiple(&[msg, msg2]);
/// ```
#[cfg(any(feature = "sgx", feature = "std"))]
#[allow(unused_imports)]
pub fn prepare_hash_multiple<B: AsRef<[u8]>>(messages: &[B]) -> crate::localstd::vec::Vec<u8> {
use crate::localstd::{vec::Vec, mem};
let mut res = Vec::with_capacity(messages.len() * mem::size_of::<usize>());
Expand Down
1 change: 1 addition & 0 deletions enigma-principal/enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![feature(slice_concat_ext)]

#![deny(unused_extern_crates)]
#![allow(unused_attributes)] // https://github.com/rust-lang/rust/issues/60050

extern crate enigma_crypto;
extern crate enigma_tools_m;
Expand Down
4 changes: 2 additions & 2 deletions enigma-tools-m/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rustc-hex = { version = "2.0.1", default-features = false }
ethabi_std = { package = "ethabi", version = "6.0.1", optional = true }
ethereum_types_std = { package = "ethereum-types", version = "0.4", optional = true }
rmp_serde_std = { package = "rmp-serde", git = "https://github.com/3Hren/msgpack-rust.git", optional = true }
serde_std = { package = "serde", version = "1.0", default-features = false, optional = true }
serde_std = { package = "serde", version = "1.0", default-features = false, features = ["derive"], optional = true }
serde_json_std = { package = "serde_json", version = "1.0", optional = true }


Expand All @@ -28,7 +28,7 @@ ethabi_sgx = { package = "ethabi", git = "https://github.com/enigmampc/ethabi.gi
ethereum_types_sgx = { package = "ethereum-types", git = "https://github.com/enigmampc/primitives.git", rev = "sgx-v0.4.0", default-features = false, optional = true }
rmp_serde_sgx = { package = "rmp-serde", git = "https://github.com/enigmampc/msgpack-rust.git", rev = "0.14.0-sgx-1.0.8", optional = true }
sgx_tstd = { git = "https://github.com/baidu/rust-sgx-sdk.git", rev = "v1.0.8", optional = true }
serde_sgx = { package = "serde", git = "https://github.com/mesalock-linux/serde-sgx.git", rev = "407aaaa2558dda5c2367d57ba40324c52cf9acc2", default-features = false, optional = true }
serde_sgx = { package = "serde", git = "https://github.com/mesalock-linux/serde-sgx.git", rev = "407aaaa2558dda5c2367d57ba40324c52cf9acc2", default-features = false, features = ["derive"], optional = true }
serde_json_sgx = { package = "serde_json", git = "https://github.com/enigmampc/serde-json-sgx.git", rev = "1.0.39-sgx-1.0.8", optional = true }

[features]
Expand Down
9 changes: 6 additions & 3 deletions enigma-tools-m/src/primitives/km_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ use enigma_types::{ContractAddress, DhKey, PubKey, StateKey};

pub type MsgID = [u8; 12];

#[derive(Debug, PartialEq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(crate = "crate::serde")]
pub enum PrincipalMessageType {
Response(Vec<(ContractAddress, StateKey)>),
Request(Option<Vec<ContractAddress>>),
EncryptedResponse(Vec<u8>),
}

#[derive(Debug, PartialEq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(crate = "crate::serde")]
pub struct PrincipalMessage {
pub data: PrincipalMessageType,
pub(crate) pubkey: Vec<u8>,
Expand Down Expand Up @@ -131,7 +133,8 @@ impl<'a> Encryption<&'a DhKey, CryptoError, Self, [u8; 12]> for PrincipalMessage
}
}

#[derive(Debug, PartialEq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(crate = "crate::serde")]
pub struct UserMessage {
pub(crate) pubkey: Vec<u8>,
}
Expand Down
3 changes: 1 addition & 2 deletions enigma-tools-m/src/primitives/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod km_primitives;
pub mod serde_impls;
pub mod km_primitives;
224 changes: 0 additions & 224 deletions enigma-tools-m/src/primitives/serde_impls.rs

This file was deleted.

4 changes: 2 additions & 2 deletions enigma-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ categories = ["no-std"]
[dependencies]
rustc-hex = { version = "2.0.1", default-features = false }
arrayvec = { version = "0.4.10", default-features = false }
serde_sgx = { package = "serde", git = "https://github.com/mesalock-linux/serde-sgx.git", rev = "407aaaa2558dda5c2367d57ba40324c52cf9acc2", optional = true }
serde_std = { package = "serde", version = "1.0", default-features = false }
serde_sgx = { package = "serde", git = "https://github.com/mesalock-linux/serde-sgx.git", rev = "407aaaa2558dda5c2367d57ba40324c52cf9acc2", features = ["derive"], optional = true }
serde_std = { package = "serde", version = "1.0", default-features = false, features = ["derive"] }

[build-dependencies]
cbindgen = "0.8"
Expand Down
49 changes: 4 additions & 45 deletions enigma-types/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use core::ops::{Deref, DerefMut};
use rustc_hex::{FromHex, FromHexError};
use arrayvec::ArrayVec;
use crate::serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
#[serde(crate = "crate::serde")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
pub struct Hash256([u8; 32]);


Expand Down Expand Up @@ -65,50 +68,6 @@ impl AsMut<[u8]> for Hash256 {
}
}

use crate::serde::de::{SeqAccess, Error};
use core::fmt::{self, Formatter};
use crate::serde::{Serialize, Deserialize, Serializer, Deserializer, de::Visitor};

impl Serialize for Hash256 {
fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error> where S: Serializer {
Serializer::serialize_newtype_struct(ser, "Hash256", &self.0)
}
}

struct Hash256Visitor;

impl<'de> Visitor<'de> for Hash256Visitor {
type Value = Hash256;
fn expecting(&self, fmt: &mut Formatter) -> fmt::Result {
fmt.write_str("tuple struct Hash256")
}

fn visit_newtype_struct<E>(self, err: E) -> Result<Self::Value, E::Error> where E: Deserializer<'de>, {

match <[u8; 32] as Deserialize>::deserialize(err) {
Ok(field) => Ok(Hash256(field)),
Err(err) => Err(err),
}
}

fn visit_seq<A>(self, mut seq: A ) -> Result<Self::Value, A::Error> where A: SeqAccess<'de> {
match seq.next_element::<[u8; 32]>() {
Ok(v) => match v {
Some(field) => Ok(Hash256(field)),
None => Err(Error::invalid_length(0, &"tuple struct Hash256 with 1 element" )),
},
Err(err) => Err(err)
}
}
}


impl<'de> Deserialize<'de> for Hash256 {
fn deserialize<D>(des: D) -> Result<Self, D::Error> where D: Deserializer<'de>, {
des.deserialize_newtype_struct("Hash256", Hash256Visitor)
}
}

#[cfg(test)]
mod test {
use super::Hash256;
Expand Down
Loading

0 comments on commit b24c4f6

Please sign in to comment.