Browse Source

Different transport for std and no_std

master
ennucore 5 years ago
parent
commit
e7b211dc6c
  1. 2
      src/crypto.rs
  2. 2
      src/ironforce.rs
  3. 2
      src/lib.rs
  4. 1
      src/message.rs
  5. 31
      src/transport.rs
  6. 6
      src/way.rs

2
src/crypto.rs

@ -3,10 +3,8 @@ extern crate rand_os;
extern crate ed25519_dalek; extern crate ed25519_dalek;
use ed25519_dalek::{PublicKey as PK, Keypair, Signature}; use ed25519_dalek::{PublicKey as PK, Keypair, Signature};
use sha2::Sha512;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use rand::rngs::OsRng; use rand::rngs::OsRng;
use self::ed25519_dalek::Digest;
use alloc::vec::Vec; use alloc::vec::Vec;

2
src/ironforce.rs

@ -12,7 +12,7 @@ pub struct IronForce {
impl IronForce { impl IronForce {
pub fn new() -> 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<u8>) -> Message { fn new_message(&self, msg_type: MsgType, body: Vec<u8>) -> Message {

2
src/lib.rs

@ -1,4 +1,3 @@
#![feature(alloc)]
#![no_std] #![no_std]
extern crate alloc; extern crate alloc;
@ -9,6 +8,7 @@ mod transport;
mod message; mod message;
mod crypto; mod crypto;
mod error; mod error;
mod way;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

1
src/message.rs

@ -3,7 +3,6 @@ use sha2::Digest;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use alloc::vec::Vec; use alloc::vec::Vec;
use pinecone::{from_bytes, to_vec}; use pinecone::{from_bytes, to_vec};
use ed25519_dalek::Signature;
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]

31
src/transport.rs

@ -1,9 +1,40 @@
use crate::message::{Message, MsgType}; use crate::message::{Message, MsgType};
use crate::way::Way;
use alloc::vec::Vec; use alloc::vec::Vec;
use alloc::boxed::Box;
#[cfg(no_std)]
pub struct Transport {} pub struct Transport {}
#[cfg(not(no_std))]
pub struct Transport {
ways: Vec<Box<dyn Way>>
}
#[cfg(no_std)]
impl Transport { impl Transport {
pub fn new() -> Self {
Self {}
}
pub fn send(&self, msg: &Message) {
}
pub fn receive(&self) -> Message {
Message::new(MsgType::Service,
Vec::<u8>::new(),
&crate::crypto::KeyPack::gen())
}
}
#[cfg(not(no_std))]
impl Transport {
pub fn new() -> Self {
Self {ways: Vec::<Box<dyn Way>>::new()}
}
pub fn send(&self, msg: &Message) { pub fn send(&self, msg: &Message) {
} }

6
src/way.rs

@ -0,0 +1,6 @@
use crate::message::Message;
pub trait Way {
fn send(&self, msg: &Message);
fn receive(&self) -> Message;
}
Loading…
Cancel
Save