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 25, 2024
1 parent 2ae26ba commit c030b82
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 31 deletions.
8 changes: 3 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,8 @@ 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" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "046478b7a4f6e2315acf9112d98308379c2e3eee" }
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", tag = "v0.1.0-nitrokey.18" }
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
12 changes: 6 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,8 @@ 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());
#[allow(clippy::unwrap_used)]
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
14 changes: 5 additions & 9 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 All @@ -34,16 +34,12 @@ fn migrate_single(fs: &dyn DynFilesystem, path: &Path) -> Result<(), Error> {
/// Migrate does not itself keep track of whether the migration was performed
///
/// ```rust
///# use littlefs2::{fs::Filesystem, const_ram_storage, path};
///# use trussed::types::{LfsResult, LfsStorage};
///# use littlefs2_core::{DynFilesystem, Error, path};
///# use trussed_auth::migrate::migrate_remove_dat;
///# const_ram_storage!(Storage, 4096);
///# let mut storage = Storage::new();
///# Filesystem::format(&mut storage);
///# Filesystem::mount_and_then(&mut storage, |fs| {
///# fn test(fs: &dyn DynFilesystem) -> Result<(), Error> {
/// migrate_remove_dat(fs, &[path!("secrets"), path!("opcard")])?;
///# Ok(())
///# }).unwrap();
///# }
/// ```
pub fn migrate_remove_dat(fs: &dyn DynFilesystem, apps: &[&Path]) -> Result<(), Error> {
for p in once(&path!("/")).chain(apps) {
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 c030b82

Please sign in to comment.