Skip to content

Commit

Permalink
Update littlefs2 to v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-nitrokey committed Oct 22, 2024
1 parent 2ae26ba commit 856b1d8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde-byte-array = "0.1.2"
sha2 = { version = "0.10.6", default-features = false }
subtle = { version = "2.4.1", default-features = false }
trussed = { version = "0.1.0", features = ["serde-extensions"] }
littlefs2 = "0.4.0"
littlefs2-core = "0.1.0"

[dev-dependencies]
quickcheck = { version = "1.0.3", default-features = false }
Expand All @@ -32,10 +32,10 @@ serde_cbor = { version = "0.11.2", features = ["std"] }
hex-literal = "0.4.1"

[patch.crates-io]
littlefs2 = { git = "https://github.com/sosthene-nitrokey/littlefs2.git", rev = "2b45a7559ff44260c6dd693e4cb61f54ae5efc53" }
trussed = { git = "https://github.com/Nitrokey/trussed.git", tag = "v0.1.0-nitrokey.19" }
littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", branch = "release-0.5.0" }
littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", branch = "release-0.5.0" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", branch = "littlefs2" }
trussed-manage = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "manage-v0.1.0" }
apdu-dispatch = { git = "https://github.com/trussed-dev/apdu-dispatch.git", rev = "915fc237103fcecc29d0f0b73391f19abf6576de" }
ctaphid-dispatch = { git = "https://github.com/trussed-dev/ctaphid-dispatch.git", rev = "57cb3317878a8593847595319aa03ef17c29ec5b" }
admin-app = { git = "https://github.com/Nitrokey/admin-app.git", tag = "v0.1.0-nitrokey.12" }
admin-app = { git = "https://github.com/Nitrokey/admin-app.git", branch = "littlefs2-core" }
cbor-smol = { git = "https://github.com/Nitrokey/cbor-smol.git", tag = "v0.4.0-nitrokey.2" }
5 changes: 1 addition & 4 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ mod data;
use core::fmt;

use hkdf::Hkdf;
use littlefs2::{
path,
path::{Path, PathBuf},
};
use littlefs2_core::{path, Path, PathBuf};
use rand_core::{CryptoRng, RngCore};
use sha2::Sha256;
use trussed::{
Expand Down
2 changes: 1 addition & 1 deletion src/backend/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::ops::Deref;

use chacha20poly1305::ChaCha8Poly1305;
use hmac::{Hmac, Mac};
use littlefs2::path;
use littlefs2_core::path;
use serde::{Deserialize, Serialize};
use serde_byte_array::ByteArray;
use sha2::{Digest as _, Sha256};
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ pub mod migrate;

use core::str::FromStr;

use littlefs2::{
path,
path::{Path, PathBuf},
};
use littlefs2_core::{path, Path, PathBuf};
use serde::{Deserialize, Serialize};
use trussed::{config::MAX_SHORT_DATA_LENGTH, types::Bytes};

Expand Down Expand Up @@ -129,7 +126,9 @@ impl PinId {
path[0..4].copy_from_slice(b"pin.");
path[4..].copy_from_slice(&self.hex());

PathBuf::from(&path)
// path has only ASCII characters and is not too long
#[allow(clippy::unwrap_used)]
PathBuf::try_from(&path).ok().unwrap()
}

/// Get the hex representation of the PIN id
Expand Down Expand Up @@ -182,7 +181,7 @@ mod tests {
for i in 0..=u8::MAX {
assert_eq!(Ok(PinId(i)), PinId::from_path(PinId(i).path().as_ref()));
let actual = PinId(i).path();
let expected = PathBuf::from(format!("pin.{i:02x}").as_str());
let expected = PathBuf::try_from(format!("pin.{i:02x}").as_str()).unwrap();
println!("id: {i}, actual: {actual}, expected: {expected}");
assert_eq!(actual, expected);
}
Expand Down
4 changes: 2 additions & 2 deletions src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use core::iter::once;

use littlefs2::{io::Error, object_safe::DynFilesystem, path, path::Path};
use littlefs2_core::{path, DynFilesystem, Error, Path};

fn migrate_single(fs: &dyn DynFilesystem, path: &Path) -> Result<(), Error> {
let path = path.join(path!("backend-auth"));
Expand All @@ -22,7 +22,7 @@ fn migrate_single(fs: &dyn DynFilesystem, path: &Path) -> Result<(), Error> {
});
match dir_res {
Ok(()) => fs.remove_dir(&path_dat),
Err(Error::NoSuchEntry) => Ok(()),
Err(Error::NO_SUCH_ENTRY) => Ok(()),
Err(_) => dir_res,
}
}
Expand Down
15 changes: 9 additions & 6 deletions tests/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ mod dispatch {
}
}

use littlefs2_core::path;
use rand_core::{OsRng, RngCore as _};
use trussed::{
backend::BackendId,
Expand Down Expand Up @@ -651,9 +652,10 @@ fn delete_all_pins() {
assert!(reply.has_pin);
let reply = syscall!(client.has_pin(Pin::Admin));
assert!(reply.has_pin);
assert!(try_syscall!(
client.read_file(Location::Internal, PathBuf::from("/backend-auth/pin.00"))
)
assert!(try_syscall!(client.read_file(
Location::Internal,
PathBuf::from(path!("/backend-auth/pin.00"))
))
.is_err());

syscall!(client.reset_app_keys());
Expand Down Expand Up @@ -740,9 +742,10 @@ fn reset_auth_data() {
assert!(reply.has_pin);
let reply = syscall!(client.has_pin(Pin::Admin));
assert!(reply.has_pin);
assert!(try_syscall!(
client.read_file(Location::Internal, PathBuf::from("/backend-auth/pin.00"))
)
assert!(try_syscall!(client.read_file(
Location::Internal,
PathBuf::from(path!("/backend-auth/pin.00"))
))
.is_err());

syscall!(client.reset_auth_data());
Expand Down

0 comments on commit 856b1d8

Please sign in to comment.