clean up lifetimes
Some checks are pending
CI / Check (push) Waiting to run
CI / Test Suite (push) Waiting to run
CI / Rustfmt (push) Waiting to run
CI / Clippy (push) Waiting to run
CI / cargo-deny (push) Waiting to run

This commit is contained in:
Grimmauld 2025-02-13 23:01:49 +01:00
parent 7d3600d684
commit ef953aed58
No known key found for this signature in database
3 changed files with 25 additions and 34 deletions

View file

@ -10,6 +10,10 @@ regex = "1.11.1"
sha1 = "0.10.6" sha1 = "0.10.6"
sha2 = "0.10.8" sha2 = "0.10.8"
[[example]]
name = "example"
path = "./src/example.rs"
[package] [package]
name = "lib_ykoath2" name = "lib_ykoath2"
version = "0.1.0" version = "0.1.0"
@ -17,7 +21,3 @@ edition = "2021"
authors = ["Grimmauld <grimmauld@grimmauld.de>"] authors = ["Grimmauld <grimmauld@grimmauld.de>"]
description = "experiments with smartcards" description = "experiments with smartcards"
license-file = "LICENSE" license-file = "LICENSE"
[[example]]
name = "example"
path = "./src/example.rs"

View file

@ -1,9 +1,13 @@
[advisories] [advisories]
db-path = "~/.cargo/advisory-db" db-path = "~/.cargo/advisory-db"
db-urls = ["https://github.com/rustsec/advisory-db"] db-urls = ["https://github.com/rustsec/advisory-db"]
ignore = [] ignore = []
[bans]
multiple-versions = "deny"
wildcards = "deny"
highlight = "all"
[licenses] [licenses]
allow = [ allow = [
"MIT", # from ouroboros "MIT", # from ouroboros
@ -11,8 +15,3 @@ allow = [
"ISC", # from iso7816-tlv "ISC", # from iso7816-tlv
"BSD-3-Clause" "BSD-3-Clause"
] ]
[bans]
multiple-versions = "deny"
wildcards = "deny"
highlight = "all"

View file

@ -44,24 +44,19 @@ fn _hmac_shorten_key(key: &[u8], algo: HashAlgo) -> Vec<u8> {
} }
} }
pub struct OathSession<'a> { pub struct OathSession {
version: &'a [u8], version: Vec<u8>,
salt: &'a [u8], salt: Vec<u8>,
challenge: &'a [u8], challenge: Vec<u8>,
transaction_context: TransactionContext, transaction_context: TransactionContext,
pub name: String, pub name: String,
} }
fn clone_with_lifetime(data: &[u8]) -> Vec<u8> {
// Clone the slice into a new Vec<u8>
data.to_vec() // `to_vec()` will return a Vec<u8> that has its own ownership
}
pub struct RefreshableOathCredential<'a> { pub struct RefreshableOathCredential<'a> {
pub cred: OathCredential, pub cred: OathCredential,
pub code: Option<OathCodeDisplay>, pub code: Option<OathCodeDisplay>,
pub valid_timeframe: Range<SystemTime>, pub valid_timeframe: Range<SystemTime>,
refresh_provider: &'a OathSession<'a>, refresh_provider: &'a OathSession,
} }
impl Display for RefreshableOathCredential<'_> { impl Display for RefreshableOathCredential<'_> {
@ -75,7 +70,7 @@ impl Display for RefreshableOathCredential<'_> {
} }
impl<'a> RefreshableOathCredential<'a> { 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 { RefreshableOathCredential {
cred, cred,
code: None, code: None,
@ -135,7 +130,7 @@ impl<'a> RefreshableOathCredential<'a> {
} }
} }
impl OathSession<'_> { impl OathSession {
pub fn new(name: &str) -> Result<Self, Error> { pub fn new(name: &str) -> Result<Self, Error> {
let transaction_context = TransactionContext::from_name(name)?; let transaction_context = TransactionContext::from_name(name)?;
let info_buffer = let info_buffer =
@ -151,25 +146,22 @@ impl OathSession<'_> {
version: info_map version: info_map
.get(&(Tag::Version as u8)) .get(&(Tag::Version as u8))
.unwrap_or(&vec![0u8; 0]) .unwrap_or(&vec![0u8; 0])
.to_owned() .to_owned(),
.leak(),
salt: info_map salt: info_map
.get(&(Tag::Name as u8)) .get(&(Tag::Name as u8))
.unwrap_or(&vec![0u8; 0]) .unwrap_or(&vec![0u8; 0])
.to_owned() .to_owned(),
.leak(),
challenge: info_map challenge: info_map
.get(&(Tag::Challenge as u8)) .get(&(Tag::Challenge as u8))
.unwrap_or(&vec![0u8; 0]) .unwrap_or(&vec![0u8; 0])
.to_owned() .to_owned(),
.leak(),
name: name.to_string(), name: name.to_string(),
transaction_context, transaction_context,
}) })
} }
pub fn get_version(&self) -> &[u8] { pub fn get_version(&self) -> &[u8] {
self.version &self.version
} }
pub fn rename_credential( pub fn rename_credential(