Skip to content

Commit

Permalink
Update nitrokey-rs to 16f6c38 (branch backend)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinkrahl committed Feb 24, 2022
1 parent 81554c7 commit a81c318
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 28 deletions.
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

0 comments on commit a81c318

Please sign in to comment.