From e7b211dc6c7cc541b1eb6ab25104c0cbe10b6b28 Mon Sep 17 00:00:00 2001 From: ennucore Date: Fri, 20 Mar 2020 12:42:21 +0300 Subject: [PATCH] Different transport for std and no_std --- src/crypto.rs | 2 -- src/ironforce.rs | 2 +- src/lib.rs | 2 +- src/message.rs | 1 - src/transport.rs | 31 +++++++++++++++++++++++++++++++ src/way.rs | 6 ++++++ 6 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/way.rs diff --git a/src/crypto.rs b/src/crypto.rs index d74ce05..b76ff0a 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -3,10 +3,8 @@ extern crate rand_os; extern crate ed25519_dalek; use ed25519_dalek::{PublicKey as PK, Keypair, Signature}; -use sha2::Sha512; use serde::{Serialize, Deserialize}; use rand::rngs::OsRng; -use self::ed25519_dalek::Digest; use alloc::vec::Vec; diff --git a/src/ironforce.rs b/src/ironforce.rs index 4fc5204..4fb83ce 100644 --- a/src/ironforce.rs +++ b/src/ironforce.rs @@ -12,7 +12,7 @@ pub struct IronForce { impl IronForce { pub fn new() -> IronForce { - IronForce { transport: Transport {}, key_pack: KeyPack::gen() } + IronForce { transport: Transport::new(), key_pack: KeyPack::gen() } } fn new_message(&self, msg_type: MsgType, body: Vec) -> Message { diff --git a/src/lib.rs b/src/lib.rs index 057039f..49dccbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(alloc)] #![no_std] extern crate alloc; @@ -9,6 +8,7 @@ mod transport; mod message; mod crypto; mod error; +mod way; #[cfg(test)] mod tests { diff --git a/src/message.rs b/src/message.rs index e34bf16..3b328aa 100644 --- a/src/message.rs +++ b/src/message.rs @@ -3,7 +3,6 @@ use sha2::Digest; use serde::{Serialize, Deserialize}; use alloc::vec::Vec; use pinecone::{from_bytes, to_vec}; -use ed25519_dalek::Signature; #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] diff --git a/src/transport.rs b/src/transport.rs index 9c281fc..866400e 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -1,9 +1,40 @@ use crate::message::{Message, MsgType}; +use crate::way::Way; + use alloc::vec::Vec; +use alloc::boxed::Box; +#[cfg(no_std)] pub struct Transport {} +#[cfg(not(no_std))] +pub struct Transport { + ways: Vec> +} + +#[cfg(no_std)] impl Transport { + pub fn new() -> Self { + Self {} + } + + pub fn send(&self, msg: &Message) { + + } + + pub fn receive(&self) -> Message { + Message::new(MsgType::Service, + Vec::::new(), + &crate::crypto::KeyPack::gen()) + } +} + +#[cfg(not(no_std))] +impl Transport { + pub fn new() -> Self { + Self {ways: Vec::>::new()} + } + pub fn send(&self, msg: &Message) { } diff --git a/src/way.rs b/src/way.rs new file mode 100644 index 0000000..4c5045a --- /dev/null +++ b/src/way.rs @@ -0,0 +1,6 @@ +use crate::message::Message; + +pub trait Way { + fn send(&self, msg: &Message); + fn receive(&self) -> Message; +}