~ireas/nitrokey-rs

60a3c19dff2a0410c7f199c0651dd35aff36eec6 — Robin Krahl 4 months ago 8b87b5e
Run clippy for all targets

This patch changes the clippy configuration so that it is executed for
all targets, including tests and examples.  It also fixes the clippy
issues that we currently have in these targets.

Fixes: https://todo.sr.ht/~ireas/nitrokey-rs/10
5 files changed, 9 insertions(+), 16 deletions(-)

M Makefile
M src/device/mod.rs
M tests/device.rs
M tests/lib.rs
M tests/pws.rs
M Makefile => Makefile +1 -1
@@ 46,7 46,7 @@ check:
.PHONY: lint
lint: check
	$(CARGO) fmt -- --check
	$(CARGO) clippy -- -D warnings
	$(CARGO) clippy --all-targets -- -D warnings
	reuse lint

.PHONY: fix

M src/device/mod.rs => src/device/mod.rs +1 -5
@@ 741,11 741,7 @@ mod tests {
        fn assert_err(s: &str) {
            match SerialNumber::from_str(s).unwrap_err() {
                super::Error::LibraryError(LibraryError::InvalidHexString) => {}
                err => assert!(
                    false,
                    "expected InvalidHexString error, got {} (input {})",
                    err, s
                ),
                err => panic!("expected InvalidHexString error, got {} (input {})", err, s),
            }
        }


M tests/device.rs => tests/device.rs +5 -5
@@ 26,7 26,7 @@ fn count_nitrokey_block_devices() -> usize {
        .output()
        .expect("Could not list block devices");
    String::from_utf8_lossy(&output.stdout)
        .split("\n")
        .split('\n')
        .filter(|&s| s.replace("_", " ") == "Nitrokey Storage")
        .count()
}


@@ 175,7 175,7 @@ where
        Err((device, _)) => device,
    };
    assert_ok!(count, device.get_admin_retry_count());
    return device;
    device
}

fn user_retry<'a, T>(device: T, suffix: &str, count: u8) -> T


@@ 188,7 188,7 @@ where
        Err((device, _)) => device,
    };
    assert_ok!(count, device.get_user_retry_count());
    return device;
    device
}

#[test_device]


@@ 300,7 300,7 @@ where
    let err = result.unwrap_err();
    match err.1 {
        Error::CommandError(err) => assert_eq!(error, err),
        _ => assert!(false),
        _ => panic!("expected failed user login"),
    };
    err.0
}


@@ 565,7 565,7 @@ fn set_unencrypted_volume_mode(device: Storage) {
            (),
            device.set_unencrypted_volume_mode(DEFAULT_ADMIN_PIN, mode)
        );
        assert_mode(&device, mode);
        assert_mode(device, mode);
    }

    let mut device = device;

M tests/lib.rs => tests/lib.rs +1 -1
@@ 7,7 7,7 @@ mod util;
fn get_library_version() {
    let version = unwrap_ok!(nitrokey::get_library_version());

    assert!(version.git.is_empty() || version.git.starts_with("v"));
    assert!(version.git.is_empty() || version.git.starts_with('v'));
    assert!(version.major > 0);
}


M tests/pws.rs => tests/pws.rs +1 -4
@@ 10,7 10,7 @@ use nitrokey::{
    CommandError, Device, Error, GetPasswordSafe, LibraryError, PasswordSafe, PasswordSlot,
    DEFAULT_ADMIN_PIN, DEFAULT_USER_PIN,
};
use nitrokey_sys;

use nitrokey_test::test as test_device;

fn get_slot_name_direct(slot: u8) -> Result<String, Error> {


@@ 118,7 118,6 @@ fn get_data(device: DeviceWrapper) {
    assert_ok!("name".to_string(), slot.get_name());
    assert_ok!("login".to_string(), slot.get_login());
    assert_ok!("password".to_string(), slot.get_password());
    drop(slot);

    assert_ok!((), pws.erase_slot(1));



@@ 127,7 126,6 @@ fn get_data(device: DeviceWrapper) {
    assert_ok!(String::new(), slot.get_name());
    assert_ok!(String::new(), slot.get_login());
    assert_ok!(String::new(), slot.get_password());
    drop(slot);

    let name = "with å";
    let login = "pär@test.com";


@@ 138,7 136,6 @@ fn get_data(device: DeviceWrapper) {
    assert_ok!(name.to_string(), slot.get_name());
    assert_ok!(login.to_string(), slot.get_login());
    assert_ok!(password.to_string(), slot.get_password());
    drop(slot);

    let slot_count = pws.get_slot_count();
    assert_lib_err!(LibraryError::InvalidSlot, pws.get_slot(slot_count));