From 9542bbb670a2b20ef8109cb69eaf1d1dfe155f1f Mon Sep 17 00:00:00 2001 From: Kai Jan Kriegel Date: Sat, 12 Mar 2022 10:49:08 +0100 Subject: [PATCH] create file with maximum size transaction size for convenience --- src/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index ce66e97..f6c1411 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,7 +126,12 @@ fn main() -> Result<(), Box> { println!("Contact URI: {}", contact_uri); let token = match args.token { - Some(token) => token, + Some(token) => { + if token.as_bytes().len() >= MAX_BYTES_PER_TRANSACTION { + return Err("Token is too long".into()) + } + token + }, None => { Uuid::new_v4().to_string() } @@ -185,7 +190,7 @@ fn main() -> Result<(), Box> { // create file with token let token_accessrights = generate_file_access_rights(FileAccessRights::FREE as u8, 0x00, 0x00, 0x00)?; - desfire.create_file_standard(0x03, FileCommunication::PLAIN, token_accessrights, token.as_bytes().len() as u32)?; + desfire.create_file_standard(0x03, FileCommunication::PLAIN, token_accessrights, MAX_BYTES_PER_TRANSACTION as u32)?; // Max desfire.write_data(0x03, 0x00, token.as_bytes())?; println!("created token file");