Commit 7d225631 authored by SamwiseFilmore's avatar SamwiseFilmore

Make argon2 optional

Resolves #26.

Since dirs is a reverse dependency of this crate and is used an awful
lot, it's nice to have as small a dependency footprint as possible. dirs
doesn't need the authentication stuff so we can drop a large number of
deps. I imagine this will probably be useful in other contexts as well.
parent 4afae396
Pipeline #8389 failed with stages
in 1 minute and 24 seconds
......@@ -20,7 +20,9 @@ test:linux:
stage: test
dependencies:
- build:linux
script: cargo +nightly test --verbose
script:
- cargo +nightly test --verbose
- cargo +nightly test --verbose --no-default-features
test:redox:
stage: test
......
......@@ -10,6 +10,14 @@ readme = "README.md"
keywords = ["redox", "auth"]
[dependencies]
rust-argon2 = "0.8"
rust-argon2 = { version = "0.8", optional = true }
getrandom = "0.1"
redox_syscall = "0.1"
[features]
default = ["auth"]
# Enable password authentication using argon2. Some API may not be available
# without default features.
auth = ["rust-argon2"]
......@@ -26,6 +26,7 @@
//! schemes for redox in future without breakage of existing
//! software.
#[cfg(feature = "auth")]
extern crate argon2;
extern crate getrandom;
extern crate syscall;
......@@ -43,6 +44,7 @@ use std::process::Command;
use std::slice::{Iter, IterMut};
use std::str::FromStr;
#[cfg(not(test))]
#[cfg(feature = "auth")]
use std::thread;
use std::time::Duration;
......@@ -200,6 +202,7 @@ impl User {
/// # Panics
/// If the User's hash fields are unpopulated, this function will `panic!`
/// (see [`AllUsers`](struct.AllUsers.html#shadowfile-handling) for more info).
#[cfg(feature = "auth")]
pub fn set_passwd(&mut self, password: impl AsRef<str>) -> Result<()> {
self.panic_if_unpopulated();
let password = password.as_ref();
......@@ -240,6 +243,7 @@ impl User {
/// # Panics
/// If the User's hash fields are unpopulated, this function will `panic!`
/// (see [`AllUsers`](struct.AllUsers.html#shadowfile-handling) for more info).
#[cfg(feature = "auth")]
pub fn verify_passwd(&self, password: impl AsRef<str>) -> bool {
self.panic_if_unpopulated();
// Safe because it will have panicked already if self.hash.is_none()
......@@ -1068,6 +1072,7 @@ mod test {
}
// *** struct.User ***
#[cfg(feature = "auth")]
#[test]
#[should_panic(expected = "Hash not populated!")]
fn wrong_attempt_set_password() {
......@@ -1084,6 +1089,7 @@ mod test {
user.unset_passwd();
}
#[cfg(feature = "auth")]
#[test]
#[should_panic(expected = "Hash not populated!")]
fn wrong_attempt_verify_password() {
......@@ -1108,6 +1114,7 @@ mod test {
user.is_passwd_unset();
}
#[cfg(feature = "auth")]
#[test]
fn attempt_user_api() {
let mut users = AllUsers::new(test_auth_cfg()).unwrap();
......@@ -1193,6 +1200,7 @@ mod test {
}
}
#[cfg(feature = "auth")]
#[test]
fn manip_user() {
let mut users = AllUsers::new(test_auth_cfg()).unwrap();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment