Skip to content

Commit

Permalink
Closes #45, closes #46, closes #48 rust build
Browse files Browse the repository at this point in the history
  • Loading branch information
adria0 committed Jan 20, 2020
1 parent 5d60b05 commit d8fa4f1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 39 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --all-features --verbose
run: RUSTFLAGS="-D warnings" cargo build --verbose --all-features --all-targets
- name: Build no features
run: cargo build --verbose
- name: Build sync
run: cargo build --verbose --features "sync"
- name: Build async_std
run: cargo build --verbose --features "async_std"
- name: Build async_std tokio_compat
run: cargo build --verbose --features "async_std tokio_compat"
5 changes: 5 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage:
status:
patch:
default:
enabled: no
3 changes: 1 addition & 2 deletions examples/handshake-boxstream-bench-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ extern crate base64;
extern crate kuska_handshake;

use std::env;
use async_std::io::{self, Read,Write};
use async_std::io;
use async_std::net::{TcpStream, TcpListener};

use sodiumoxide::crypto::{auth, sign::ed25519};

use kuska_handshake::KeyNonce;
use kuska_handshake::async_std::{handshake_client, handshake_server, BoxStream, Error};

const BUF_SIZE: usize = 0x8000;
Expand Down
24 changes: 5 additions & 19 deletions src/async_std/circularbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,6 @@ impl CircularBuffer {
self.end = 0;
self.len = 0;
}
pub fn write_from<R: Read>(&mut self, reader : &mut R) -> io::Result<()> {
let mut readed = 1;

loop {
if readed==0 || self.len == self.buffer.len() {
return Ok(())
} else if self.start <= self.end {
// write at %end -> end_buffer
readed = reader.read(&mut self.buffer[self.end..])?;
self.end = (readed + self.end) % self.buffer.len();
} else {
// write at %end -> %start
readed = reader.read(&mut self.buffer[self.end..self.start])?;
self.end += readed;
}
self.len += readed;
}
}

pub fn defrag(&mut self) {
if self.len > 0 {
Expand Down Expand Up @@ -276,7 +258,11 @@ mod test {
// skip 3
b.skip(3);
assert_eq!("08", hex::encode(b.contiguous_value()));


// clear
b.clear();
assert_eq!("", hex::encode(b.contiguous_value()));

Ok(())
}

Expand Down
15 changes: 15 additions & 0 deletions src/boxstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::handshake::HandshakeComplete;

use core::fmt;
use core::{cmp, mem};
use std::convert;
use std::io;
use sodiumoxide::crypto::{auth, hash::sha256, scalarmult::curve25519, secretbox};

// Length of encrypted body (with MAC detached)
Expand All @@ -20,6 +22,19 @@ pub enum Error {
DecryptBodySecretbox,
}

impl std::error::Error for Error {}

impl convert::From<Error> for io::Error {
fn from(error: Error) -> Self {
match error {
Error::DecryptHeaderSecretbox => {
Self::new(io::ErrorKind::InvalidInput, error)
}
Error::DecryptBodySecretbox => Self::new(io::ErrorKind::InvalidInput, error),
}
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
17 changes: 2 additions & 15 deletions src/sync/boxstream.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
use std::{convert, io, io::Read, io::Write};
use std::{io, io::Read, io::Write};

use crate::boxstream::{
self, BoxStreamRecv, BoxStreamSend, KeyNonce, MSG_BODY_MAX_LEN, MSG_HEADER_LEN,
BoxStreamRecv, BoxStreamSend, KeyNonce, MSG_BODY_MAX_LEN, MSG_HEADER_LEN,
};
use crate::handshake::HandshakeComplete;

impl std::error::Error for boxstream::Error {}

impl convert::From<boxstream::Error> for io::Error {
fn from(error: boxstream::Error) -> Self {
match error {
boxstream::Error::DecryptHeaderSecretbox => {
Self::new(io::ErrorKind::InvalidInput, error)
}
boxstream::Error::DecryptBodySecretbox => Self::new(io::ErrorKind::InvalidInput, error),
}
}
}

pub struct BoxStreamRead<R> {
stream: R,
bs_recv: BoxStreamRecv,
Expand Down

0 comments on commit d8fa4f1

Please sign in to comment.