Skip to content

Commit 2c9f677

Browse files
Increase size of file writing
The increased size of files is a requirement for PIV, 1kB certificates are too small. This commit also removes the `user_attribute` field that was never read anyway. This avoids increasing the total size of the interchange
1 parent 199df9d commit 2c9f677

File tree

7 files changed

+16
-22
lines changed

7 files changed

+16
-22
lines changed

src/api.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ pub mod request {
270270
WriteFile:
271271
- location: Location
272272
- path: PathBuf
273-
- data: Message
274-
- user_attribute: Option<UserAttribute>
273+
- data: LargeMessage
275274

276275
UnsafeInjectKey:
277276
- mechanism: Mechanism // -> implies key type
@@ -330,7 +329,7 @@ pub mod request {
330329

331330
WriteCertificate:
332331
- location: Location
333-
- der: Message
332+
- der: LargeMessage
334333

335334
}
336335
}
@@ -417,7 +416,7 @@ pub mod reply {
417416
- entry: Option<DirEntry>
418417

419418
ReadFile:
420-
- data: Message
419+
- data: LargeMessage
421420

422421
Metadata:
423422
- metadata: Option<crate::types::Metadata>
@@ -478,7 +477,7 @@ pub mod reply {
478477
DeleteCertificate:
479478

480479
ReadCertificate:
481-
- der: Message
480+
- der: LargeMessage
482481

483482
WriteCertificate:
484483
- id: CertId

src/client.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub trait CertificateClient: PollClient {
253253
location: Location,
254254
der: &[u8],
255255
) -> ClientResult<'_, reply::WriteCertificate, Self> {
256-
let der = Message::from_slice(der).map_err(|_| ClientError::DataTooLarge)?;
256+
let der = LargeMessage::from_slice(der).map_err(|_| ClientError::DataTooLarge)?;
257257
self.request(request::WriteCertificate { location, der })
258258
}
259259
}
@@ -645,14 +645,12 @@ pub trait FilesystemClient: PollClient {
645645
&mut self,
646646
location: Location,
647647
path: PathBuf,
648-
data: Message,
649-
user_attribute: Option<UserAttribute>,
648+
data: LargeMessage,
650649
) -> ClientResult<'_, reply::WriteFile, Self> {
651650
self.request(request::WriteFile {
652651
location,
653652
path,
654653
data,
655-
user_attribute,
656654
})
657655
}
658656
}

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use littlefs2::consts;
99
pub type MAX_APPLICATION_NAME_LENGTH = consts::U256;
1010
pub const MAX_LONG_DATA_LENGTH: usize = 1024;
1111
pub const MAX_MESSAGE_LENGTH: usize = 1024;
12+
pub const MAX_LARGE_MESSAGE_LENGTH: usize = 2048;
1213
pub type MAX_OBJECT_HANDLES = consts::U16;
1314
pub type MAX_LABEL_LENGTH = consts::U256;
1415
pub const MAX_MEDIUM_DATA_LENGTH: usize = 256;

src/store/certstore.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use littlefs2::path::PathBuf;
44
use crate::{
55
error::{Error, Result},
66
store::{self, Store},
7-
types::{CertId, Location, Message},
7+
types::{CertId, LargeMessage, Location},
88
};
99

1010
pub struct ClientCertstore<S>
@@ -18,11 +18,11 @@ where
1818

1919
pub trait Certstore {
2020
fn delete_certificate(&mut self, id: CertId) -> Result<()>;
21-
fn read_certificate(&mut self, id: CertId) -> Result<Message>;
21+
fn read_certificate(&mut self, id: CertId) -> Result<LargeMessage>;
2222
/// TODO: feels a bit heavy-weight to pass in the ClientCounterstore here
2323
/// just to ensure the next global counter ("counter zero") is used, and
2424
/// not something random.
25-
fn write_certificate(&mut self, location: Location, der: &Message) -> Result<CertId>;
25+
fn write_certificate(&mut self, location: Location, der: &[u8]) -> Result<CertId>;
2626
}
2727

2828
impl<S: Store> Certstore for ClientCertstore<S> {
@@ -36,7 +36,7 @@ impl<S: Store> Certstore for ClientCertstore<S> {
3636
.ok_or(Error::NoSuchKey)
3737
}
3838

39-
fn read_certificate(&mut self, id: CertId) -> Result<Message> {
39+
fn read_certificate(&mut self, id: CertId) -> Result<LargeMessage> {
4040
let path = self.cert_path(id);
4141
let locations = [Location::Internal, Location::External, Location::Volatile];
4242
locations
@@ -45,10 +45,10 @@ impl<S: Store> Certstore for ClientCertstore<S> {
4545
.ok_or(Error::NoSuchCertificate)
4646
}
4747

48-
fn write_certificate(&mut self, location: Location, der: &Message) -> Result<CertId> {
48+
fn write_certificate(&mut self, location: Location, der: &[u8]) -> Result<CertId> {
4949
let id = CertId::new(&mut self.rng);
5050
let path = self.cert_path(id);
51-
store::store(self.store, location, &path, der.as_slice())?;
51+
store::store(self.store, location, &path, der)?;
5252
Ok(id)
5353
}
5454
}

src/tests.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,7 @@ fn filesystem() {
532532

533533
let data = Bytes::from_slice(&[0; 20]).unwrap();
534534
block!(client
535-
.write_file(
536-
Location::Internal,
537-
PathBuf::from("test_file"),
538-
data.clone(),
539-
None,
540-
)
535+
.write_file(Location::Internal, PathBuf::from("test_file"), data.clone(),)
541536
.expect("no client error"))
542537
.expect("no errors");
543538

src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ pub type MediumData = Bytes<MAX_MEDIUM_DATA_LENGTH>;
548548
pub type ShortData = Bytes<MAX_SHORT_DATA_LENGTH>;
549549

550550
pub type Message = Bytes<MAX_MESSAGE_LENGTH>;
551+
pub type LargeMessage = Bytes<MAX_LARGE_MESSAGE_LENGTH>;
551552

552553
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
553554
pub enum KeySerialization {

tests/virt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn run_test(data: u8) {
2424

2525
// ensure that no other client is messing with our filesystem
2626
while syscall!(client.uptime()).uptime < Duration::from_secs(1) {
27-
syscall!(client.write_file(location, path.clone(), write_data.clone(), None));
27+
syscall!(client.write_file(location, path.clone(), write_data.clone()));
2828
let read_data = syscall!(client.read_file(location, path.clone())).data;
2929
assert_eq!(write_data, read_data);
3030
}

0 commit comments

Comments
 (0)