Skip to content

Commit

Permalink
Rustfmt: add config, format code, add to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sopium committed Jan 11, 2017
1 parent 623285c commit d5ae205
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reorder_imports= true
reorder_imported_names = true
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ install:
- cd libsodium-1.0.8 && ./configure --prefix=$HOME/installed_libsodium && make && make install && cd ..
- export PKG_CONFIG_PATH=$HOME/installed_libsodium/lib/pkgconfig:$PKG_CONFIG_PATH
- export LD_LIBRARY_PATH=$HOME/installed_libsodium/lib:$LD_LIBRARY_PATH
- cargo install rustfmt

rust:
- nightly

script:
- |
export PATH=$PATH:~/.cargo/bin &&
cargo fmt -- --write-mode=diff &&
cargo build &&
cargo test
4 changes: 2 additions & 2 deletions examples/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ extern crate titun;

use futures::Future;
use std::io::Result;
use std::process::{Command, Child};
use tokio_core::reactor::{Core, PollEvented};
use std::process::{Child, Command};
use titun::futures_more::repeat;
use titun::tun::Tun;
use tokio_core::reactor::{Core, PollEvented};

fn up_and_ping(name: &str) -> Result<Child> {
Command::new("ip").args(&["link", "set", name, "up"]).output()?;
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
// along with TiTun. If not, see <https://www.gnu.org/licenses/>.

use data_encoding::base64;
use map_err_io::MapErrIo;
use serde_yaml as yaml;
use sodiumoxide::crypto::secretbox::{Key, gen_key, KEYBYTES};
use sodiumoxide::crypto::secretbox::{KEYBYTES, Key, gen_key};
use std::io::{Error, ErrorKind};
use map_err_io::MapErrIo;

#[derive(Serialize, Deserialize)]
struct Config1 {
Expand Down
5 changes: 3 additions & 2 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
//! is randomly generated. Nonce is appended to ciphertext.

// TODO forward secrecy???

use byteorder::{BigEndian, ByteOrder};
use sodiumoxide::crypto::secretbox::{Key, Nonce, open, seal, NONCEBYTES};
use sodiumoxide::crypto::secretbox::{Key, NONCEBYTES, Nonce, open, seal};
use sodiumoxide::randombytes::randombytes_into;
use std::time::{SystemTime, UNIX_EPOCH};

Expand Down Expand Up @@ -78,11 +79,11 @@ fn nonce_time_in_range(n: &Nonce, max_diff: u64) -> bool {

#[cfg(test)]
mod tests {
use super::*;

use sodiumoxide::crypto::secretbox::{gen_key, gen_nonce};
use std::thread::sleep;
use std::time::Duration;
use super::*;
use test::Bencher;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/map_err_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with TiTun. If not, see <https://www.gnu.org/licenses/>.

use std::io::{Error, Result, ErrorKind};
use std::io::{Error, ErrorKind, Result};

pub trait MapErrIo<T> {
fn map_err_io(self) -> Result<T>;
Expand Down
9 changes: 4 additions & 5 deletions src/script_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// along with TiTun. If not, see <https://www.gnu.org/licenses/>.

use std::ffi::OsStr;
use std::io::{Result, Error, ErrorKind, Read, copy};
use std::io::{Error, ErrorKind, Read, Result, copy};
use std::process::{Command, Stdio};

pub struct ScriptRunner {
Expand All @@ -25,13 +25,12 @@ pub struct ScriptRunner {

impl ScriptRunner {
pub fn new() -> ScriptRunner {
ScriptRunner {
c: Command::new("sh")
}
ScriptRunner { c: Command::new("sh") }
}

pub fn env<K, V>(mut self, key: K, val: V) -> ScriptRunner
where K: AsRef<OsStr>, V: AsRef<OsStr>,
where K: AsRef<OsStr>,
V: AsRef<OsStr>
{
self.c.env(key, val);
self
Expand Down
4 changes: 2 additions & 2 deletions src/titun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
// along with TiTun. If not, see <https://www.gnu.org/licenses/>.

use config::Config;
use crypto::{encrypt, decrypt};
use crypto::{decrypt, encrypt};
use futures::{Future, Poll};
use map_err_io::MapErrIo;
use script_runner::ScriptRunner;
use sodiumoxide::crypto::secretbox::Key;
use std::cell::RefCell;
use std::io::{Error, Result, Read, Write};
use std::io::{Error, Read, Result, Write};
use std::net::SocketAddr;
use std::rc::Rc;
use systemd_notify::systemd_notify_ready;
Expand Down
8 changes: 4 additions & 4 deletions src/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// You should have received a copy of the GNU General Public License
// along with TiTun. If not, see <https://www.gnu.org/licenses/>.

use mio::{Evented, Poll, Token, Ready, PollOpt};
use mio::{Evented, Poll, PollOpt, Ready, Token};
use mio::unix::EventedFd;
use nix::fcntl::{self, fcntl, OFlag, FcntlArg};
use nix::libc::{c_int, c_char, size_t};
use nix::fcntl::{self, FcntlArg, OFlag, fcntl};
use nix::libc::{c_char, c_int, size_t};
use nix::unistd::{close, read, write};
use std::convert::From;
use std::ffi::{CStr, CString};
use std::io::{Error, ErrorKind, Read, Write, Result};
use std::io::{Error, ErrorKind, Read, Result, Write};
use std::mem;
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};

Expand Down

0 comments on commit d5ae205

Please sign in to comment.