From ef953aed5877a9499dafb388bc569a39372b06b6 Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Thu, 13 Feb 2025 23:01:49 +0100 Subject: [PATCH] clean up lifetimes --- Cargo.toml | 10 +++++----- deny.toml | 19 +++++++++---------- src/lib.rs | 30 +++++++++++------------------- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b474735..a4ecbce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,12 +4,16 @@ base64 = "0.22.1" hmac = "0.12.1" iso7816-tlv = "0.4.4" ouroboros = "0.18.5" -pbkdf2 = { version = "0.12.2", features = ["sha1"] } +pbkdf2 = {version = "0.12.2", features = ["sha1"]} pcsc = "2.9.0" regex = "1.11.1" sha1 = "0.10.6" sha2 = "0.10.8" +[[example]] +name = "example" +path = "./src/example.rs" + [package] name = "lib_ykoath2" version = "0.1.0" @@ -17,7 +21,3 @@ edition = "2021" authors = ["Grimmauld "] description = "experiments with smartcards" license-file = "LICENSE" - -[[example]] -name = "example" -path = "./src/example.rs" \ No newline at end of file diff --git a/deny.toml b/deny.toml index ee8c461..a414b84 100644 --- a/deny.toml +++ b/deny.toml @@ -1,18 +1,17 @@ - [advisories] db-path = "~/.cargo/advisory-db" db-urls = ["https://github.com/rustsec/advisory-db"] ignore = [] -[licenses] -allow = [ - "MIT", # from ouroboros - "Unicode-3.0", - "ISC", # from iso7816-tlv - "BSD-3-Clause" -] - [bans] multiple-versions = "deny" wildcards = "deny" -highlight = "all" \ No newline at end of file +highlight = "all" + +[licenses] +allow = [ + "MIT", # from ouroboros + "Unicode-3.0", + "ISC", # from iso7816-tlv + "BSD-3-Clause" +] diff --git a/src/lib.rs b/src/lib.rs index 444b20e..314a6ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,24 +44,19 @@ fn _hmac_shorten_key(key: &[u8], algo: HashAlgo) -> Vec { } } -pub struct OathSession<'a> { - version: &'a [u8], - salt: &'a [u8], - challenge: &'a [u8], +pub struct OathSession { + version: Vec, + salt: Vec, + challenge: Vec, transaction_context: TransactionContext, pub name: String, } -fn clone_with_lifetime(data: &[u8]) -> Vec { - // Clone the slice into a new Vec - data.to_vec() // `to_vec()` will return a Vec that has its own ownership -} - pub struct RefreshableOathCredential<'a> { pub cred: OathCredential, pub code: Option, pub valid_timeframe: Range, - refresh_provider: &'a OathSession<'a>, + refresh_provider: &'a OathSession, } impl Display for RefreshableOathCredential<'_> { @@ -75,7 +70,7 @@ impl Display for RefreshableOathCredential<'_> { } impl<'a> RefreshableOathCredential<'a> { - pub fn new(cred: OathCredential, refresh_provider: &'a OathSession<'a>) -> Self { + pub fn new(cred: OathCredential, refresh_provider: &'a OathSession) -> Self { RefreshableOathCredential { cred, code: None, @@ -135,7 +130,7 @@ impl<'a> RefreshableOathCredential<'a> { } } -impl OathSession<'_> { +impl OathSession { pub fn new(name: &str) -> Result { let transaction_context = TransactionContext::from_name(name)?; let info_buffer = @@ -151,25 +146,22 @@ impl OathSession<'_> { version: info_map .get(&(Tag::Version as u8)) .unwrap_or(&vec![0u8; 0]) - .to_owned() - .leak(), + .to_owned(), salt: info_map .get(&(Tag::Name as u8)) .unwrap_or(&vec![0u8; 0]) - .to_owned() - .leak(), + .to_owned(), challenge: info_map .get(&(Tag::Challenge as u8)) .unwrap_or(&vec![0u8; 0]) - .to_owned() - .leak(), + .to_owned(), name: name.to_string(), transaction_context, }) } pub fn get_version(&self) -> &[u8] { - self.version + &self.version } pub fn rename_credential(