Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nitrokey-rs to v0.10.0 #186

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ version = "0.2"
version = "0.1"

[dependencies.nitrokey]
version = "0.9.0"
git = "https://git.sr.ht/~ireas/nitrokey-rs"
branch = "backend"

[dependencies.progressing]
version = "3.0.2"
Expand Down
14 changes: 6 additions & 8 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn find_device(config: &config::Config) -> anyhow::Result<nitrokey::DeviceInfo>

/// Connect to a Nitrokey device that matches the given requirements
fn connect<'mgr>(
manager: &'mgr mut nitrokey::Manager,
manager: &'mgr nitrokey::Manager,
config: &config::Config,
) -> anyhow::Result<nitrokey::DeviceWrapper<'mgr>> {
let device_info = find_device(config)?;
Expand All @@ -131,12 +131,11 @@ fn with_device<F>(ctx: &mut Context<'_>, op: F) -> anyhow::Result<()>
where
F: FnOnce(&mut Context<'_>, nitrokey::DeviceWrapper<'_>) -> anyhow::Result<()>,
{
let mut manager =
nitrokey::take().context("Failed to acquire access to Nitrokey device manager")?;
let manager = nitrokey::take().context("Failed to acquire access to Nitrokey device manager")?;

set_log_level(ctx);

let device = connect(&mut manager, &ctx.config)?;
let device = connect(&manager, &ctx.config)?;
op(ctx, device)
}

Expand All @@ -145,8 +144,7 @@ fn with_storage_device<F>(ctx: &mut Context<'_>, op: F) -> anyhow::Result<()>
where
F: FnOnce(&mut Context<'_>, nitrokey::Storage<'_>) -> anyhow::Result<()>,
{
let mut manager =
nitrokey::take().context("Failed to acquire access to Nitrokey device manager")?;
let manager = nitrokey::take().context("Failed to acquire access to Nitrokey device manager")?;

set_log_level(ctx);

Expand All @@ -158,7 +156,7 @@ where
ctx.config.model = Some(args::DeviceModel::Storage);
}

let device = connect(&mut manager, &ctx.config)?;
let device = connect(&manager, &ctx.config)?;
if let nitrokey::DeviceWrapper::Storage(storage) = device {
op(ctx, storage)
} else {
Expand Down Expand Up @@ -518,7 +516,7 @@ pub fn list(ctx: &mut Context<'_>, no_connect: bool) -> anyhow::Result<()> {
println!(ctx, "No Nitrokey device connected")?;
} else {
println!(ctx, "USB path\tmodel\tserial number")?;
let mut manager =
let manager =
nitrokey::take().context("Failed to acquire access to Nitrokey device manager")?;

for device_info in device_infos {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn encrypted_open_close(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_storage()?;
assert!(device.get_storage_status()?.encrypted_volume.active);
assert!(!device.get_storage_status()?.hidden_volume.active);
Expand All @@ -76,7 +76,7 @@ fn encrypted_open_close(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_storage()?;
assert!(!device.get_storage_status()?.encrypted_volume.active);
assert!(!device.get_storage_status()?.hidden_volume.active);
Expand Down
4 changes: 2 additions & 2 deletions src/tests/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn hidden_create_open_close(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_storage()?;
assert!(!device.get_storage_status()?.encrypted_volume.active);
assert!(device.get_storage_status()?.hidden_volume.active);
Expand All @@ -25,7 +25,7 @@ fn hidden_create_open_close(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_storage()?;
assert!(!device.get_storage_status()?.encrypted_volume.active);
assert!(!device.get_storage_status()?.hidden_volume.active);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn lock_storage(model: nitrokey::Model) -> anyhow::Result<()> {
let out = ncli.handle(&["lock"])?;
assert!(out.is_empty());

let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_storage()?;
assert!(!device.get_storage_status()?.encrypted_volume.active);

Expand Down
8 changes: 4 additions & 4 deletions src/tests/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::*;
#[test_device]
fn unblock(model: nitrokey::Model) -> anyhow::Result<()> {
{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_model(model)?;
let (device, err) = device.authenticate_user("wrong-pin").unwrap_err();
match err {
Expand All @@ -24,7 +24,7 @@ fn unblock(model: nitrokey::Model) -> anyhow::Result<()> {
let _ = Nitrocli::new().model(model).handle(&["pin", "unblock"])?;

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_model(model)?;
assert_eq!(device.get_user_retry_count()?, 3);
}
Expand All @@ -40,7 +40,7 @@ fn set_user(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_model(model)?;
let (_, err) = device
.authenticate_user(nitrokey::DEFAULT_USER_PIN)
Expand All @@ -61,7 +61,7 @@ fn set_user(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_model(model)?;
let _ = device
.authenticate_user(nitrokey::DEFAULT_USER_PIN)
Expand Down
4 changes: 2 additions & 2 deletions src/tests/pws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nitrokey::GetPasswordSafe as _;
use super::*;

fn clear_pws(model: nitrokey::Model) -> anyhow::Result<()> {
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let mut device = manager.connect_model(model)?;
let mut pws = device.get_password_safe(nitrokey::DEFAULT_USER_PIN)?;
let slots_to_clear = pws
Expand Down Expand Up @@ -342,7 +342,7 @@ fn add_full(model: nitrokey::Model) -> anyhow::Result<()> {

// Fill all PWS slots
{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let mut device = manager.connect_model(model)?;
let mut pws = device.get_password_safe(nitrokey::DEFAULT_USER_PIN)?;
for slot in 0..pws.get_slot_count() {
Expand Down
8 changes: 4 additions & 4 deletions src/tests/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn reset(model: nitrokey::Model) -> anyhow::Result<()> {
let _ = ncli.handle(&["pin", "set", "admin"])?;

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
// Check that the admin PIN has been changed.
let device = manager.connect_model(model)?;
let _ = device.authenticate_admin(new_admin_pin).unwrap();
Expand All @@ -29,7 +29,7 @@ fn reset(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
// Check that the admin PIN has been reset.
let device = manager.connect_model(model)?;
let mut device = device
Expand Down Expand Up @@ -58,7 +58,7 @@ fn reset_only_aes_key(model: nitrokey::Model) -> anyhow::Result<()> {

// Add an entry to the PWS
{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let mut device = manager.connect_model(model)?;
let mut pws = device.get_password_safe(NEW_USER_PIN)?;
pws.write_slot(0, NAME, LOGIN, PASSWORD)?;
Expand All @@ -74,7 +74,7 @@ fn reset_only_aes_key(model: nitrokey::Model) -> anyhow::Result<()> {
// been replaced, and that 3) the changed user PIN still works, i.e.,
// we did not perform a factory reset.
{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let mut device = manager.connect_model(model)?;
let pws = device.get_password_safe(NEW_USER_PIN)?;
let slot = pws.get_slot_unchecked(0)?;
Expand Down
4 changes: 2 additions & 2 deletions src/tests/unencrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn unencrypted_set_read_write(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_storage()?;
assert!(device.get_storage_status()?.unencrypted_volume.active);
assert!(!device.get_storage_status()?.unencrypted_volume.read_only);
Expand All @@ -22,7 +22,7 @@ fn unencrypted_set_read_write(model: nitrokey::Model) -> anyhow::Result<()> {
assert!(out.is_empty());

{
let mut manager = nitrokey::force_take()?;
let manager = nitrokey::force_take()?;
let device = manager.connect_storage()?;
assert!(device.get_storage_status()?.unencrypted_volume.active);
assert!(device.get_storage_status()?.unencrypted_volume.read_only);
Expand Down