Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ branches:

os:
- linux
- osx
# - osx

language: rust

rust:
- stable
- beta
- nightly
# - beta
# - nightly

# the earliest supported stable release; we depend upon
# * >= 1.32 for uniform module paths
Expand All @@ -38,7 +38,7 @@ env:
- RUSTFLAGS="-A unknown-lints -D warnings"
matrix:
- CARGOFLAGS=""
- CARGOFLAGS="--release"
# - CARGOFLAGS="--release"

before_script:
- rustup update
Expand Down Expand Up @@ -83,28 +83,23 @@ matrix:
- name: coverage
rust: stable
os: linux
dist: xenial
sudo: required
dist: bionic

addons:
apt:
packages:
- libcurl4-openssl-dev
- libdw-dev
- libelf-dev
- libiberty-dev
- libsodium-dev
- binutils-dev
- cmake
- libssl-dev

env:
- COVERAGE=true

before_script:
- rustup update
- cargo install cargo-update || echo "cargo-update already installed"
- cargo install cargo-travis || echo "cargo-travis already installed"
- cargo install cargo-update || echo "cargo-update already installed"
- cargo install cargo-tarpaulin || echo "cargo-tarpaulin already installed"
- cargo install-update -a

script:
- cargo coveralls --exclude-pattern "_ctest.rs,_ctest.c"
- cargo build
- cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID --tests --no-fail-fast
12 changes: 7 additions & 5 deletions src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,6 @@ fn mprotect<T>(ptr: *const T, prot: Prot) {
}
}

// LCOV_EXCL_START

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -700,12 +698,14 @@ mod tests {
#[cfg(test)]
mod tests_sigsegv {
use super::*;
use std::process;

#[cfg(not(tarpaulin))]
fn assert_sigsegv<F>(f: F)
where
F: FnOnce(),
{
use std::process;

unsafe {
let pid : libc::pid_t = libc::fork();
let mut stat : libc::c_int = 0;
Expand Down Expand Up @@ -733,6 +733,10 @@ mod tests_sigsegv {
}
}

#[cfg(tarpaulin)]
fn assert_sigsegv<F>(_f: F) where F: FnOnce() {
}

#[test]
fn it_kills_attempts_to_read_while_locked() {
assert_sigsegv(|| {
Expand Down Expand Up @@ -864,5 +868,3 @@ mod tests_proven_statements {
let _ = boxed.as_mut_slice();
}
}

// LCOV_EXCL_STOP
4 changes: 0 additions & 4 deletions src/ffi/sodium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ pub(crate) fn memrandom(bytes: &mut [u8]) {
unsafe { randombytes_buf(bytes.as_mut_ptr() as *mut _, bytes.len()) }
}

// LCOV_EXCL_START

#[cfg(test)]
mod test {
use super::*;
Expand All @@ -236,5 +234,3 @@ mod test {
assert!(!memcmp(&c, &a));
}
}

// LCOV_EXCL_STOP
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// LCOV_EXCL_LINE

//! Protected-access memory for cryptographic secrets.
//!
//! Provides a convenient way to allocate and access memory for
Expand Down
4 changes: 0 additions & 4 deletions src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ impl<T: Bytes> PartialEq for RefMut<'_, T> {

impl<T: Bytes> Eq for RefMut<'_, T> {}

// LCOV_EXCL_START

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -358,5 +356,3 @@ mod tests {
Secret::<u8>::zero(|_| sodium::fail());
}
}

// LCOV_EXCL_STOP
4 changes: 0 additions & 4 deletions src/secret_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ impl<T: Bytes> PartialEq<Ref<'_, T>> for RefMut<'_, T> {

impl<T: Bytes> Eq for RefMut<'_, T> {}

// LCOV_EXCL_START

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -558,5 +556,3 @@ mod tests_proven_statements {
let _ = boxed.as_mut();
}
}

// LCOV_EXCL_STOP
4 changes: 0 additions & 4 deletions src/secret_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,6 @@ impl<T: Bytes> PartialEq<Ref<'_, T>> for RefMut<'_, T> {

impl<T: Bytes> Eq for RefMut<'_, T> {}

// LCOV_EXCL_START

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -550,5 +548,3 @@ mod test {
assert_eq!(secret_2.borrow_mut(), secret_1.borrow());
}
}

// LCOV_EXCL_STOP
39 changes: 39 additions & 0 deletions src/traits/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,42 @@ unsafe impl<T: Bytes> AsContiguousBytes for [T] {
self.as_ptr() as *mut _
}
}

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

#[derive(Copy, Clone)]
struct Byte (u8);

unsafe impl Bytes for Byte {}

#[test]
fn it_uninitializes_to_a_garbage_value() {
let b = Byte::uninitialized();

assert_eq!(b.0, GARBAGE_VALUE);
}

#[test]
fn it_reports_size_correctly() {
assert_eq!(<Byte as Bytes>::size(), 1);
}

#[test]
fn it_provides_ptr_access() {
unsafe {
let b = Byte(255);
assert_eq!(*Bytes::as_u8_ptr(&b), 255);
}
}

#[test]
fn it_provides_mut_ptr_access() {
unsafe {
let mut b = Byte(10);
*Bytes::as_mut_u8_ptr(&mut b) = 42;
assert_eq!(b.0, 42);
}
}
}