-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::UniffiCustomTypeConverter; | ||
|
||
type DateTime = chrono::DateTime<chrono::Utc>; | ||
uniffi::custom_type!(DateTime, std::time::SystemTime); | ||
|
||
impl UniffiCustomTypeConverter for chrono::DateTime<chrono::Utc> { | ||
type Builtin = std::time::SystemTime; | ||
|
||
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> { | ||
Ok(Self::from(val)) | ||
} | ||
|
||
fn from_custom(obj: Self) -> Self::Builtin { | ||
obj.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use chrono::{DateTime, Utc}; | ||
|
||
use crate::vault::{generate_totp, TotpResponse}; | ||
|
||
use super::client_vault::ClientVault; | ||
|
||
impl<'a> ClientVault<'a> { | ||
/// Generate a TOTP code from a provided key. | ||
/// | ||
/// Key can be either: | ||
/// - A base32 encoded string | ||
/// - OTP Auth URI | ||
/// - Steam URI | ||
/// | ||
pub async fn generate_totp(&'a self, key: String, time: Option<DateTime<Utc>>) -> TotpResponse { | ||
generate_totp(key, time).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use chrono::{DateTime, Utc}; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug, JsonSchema)] | ||
#[serde(rename_all = "camelCase", deny_unknown_fields)] | ||
#[cfg_attr(feature = "mobile", derive(uniffi::Record))] | ||
pub struct TotpResponse { | ||
/// Generated TOTP code | ||
pub code: String, | ||
/// Time period | ||
pub period: u32, | ||
} | ||
|
||
/// Generate a OATH or RFC 6238 TOTP code from a provided key. | ||
/// | ||
/// <https://datatracker.ietf.org/doc/html/rfc6238> | ||
/// | ||
/// Key can be either: | ||
/// - A base32 encoded string | ||
/// - OTP Auth URI | ||
/// - Steam URI | ||
/// | ||
/// Supports providing an optional time, and defaults to current system time if none is provided. | ||
pub async fn generate_totp(_key: String, _time: Option<DateTime<Utc>>) -> TotpResponse { | ||
TotpResponse { | ||
code: "000 000".to_string(), | ||
period: 30, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters