mirror of
https://github.com/LordGrimmauld/yubi-oath-rs.git
synced 2025-03-03 21:34:40 +01:00
clean up lifetimes
This commit is contained in:
parent
7d3600d684
commit
ef953aed58
3 changed files with 25 additions and 34 deletions
10
Cargo.toml
10
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 <grimmauld@grimmauld.de>"]
|
||||
description = "experiments with smartcards"
|
||||
license-file = "LICENSE"
|
||||
|
||||
[[example]]
|
||||
name = "example"
|
||||
path = "./src/example.rs"
|
19
deny.toml
19
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"
|
||||
highlight = "all"
|
||||
|
||||
[licenses]
|
||||
allow = [
|
||||
"MIT", # from ouroboros
|
||||
"Unicode-3.0",
|
||||
"ISC", # from iso7816-tlv
|
||||
"BSD-3-Clause"
|
||||
]
|
||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -44,24 +44,19 @@ fn _hmac_shorten_key(key: &[u8], algo: HashAlgo) -> Vec<u8> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct OathSession<'a> {
|
||||
version: &'a [u8],
|
||||
salt: &'a [u8],
|
||||
challenge: &'a [u8],
|
||||
pub struct OathSession {
|
||||
version: Vec<u8>,
|
||||
salt: Vec<u8>,
|
||||
challenge: Vec<u8>,
|
||||
transaction_context: TransactionContext,
|
||||
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 cred: OathCredential,
|
||||
pub code: Option<OathCodeDisplay>,
|
||||
pub valid_timeframe: Range<SystemTime>,
|
||||
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<Self, Error> {
|
||||
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(
|
||||
|
|
Loading…
Add table
Reference in a new issue