Skip to content

Commit

Permalink
Add datetime as optional input
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Oct 17, 2023
1 parent 82f32ec commit 35ee037
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/bitwarden-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ bench = false

[dependencies]
async-lock = "2.7.0"
chrono = { version = ">=0.4.26, <0.5", features = [
"serde",
"std",
], default-features = false }
env_logger = "0.10.0"
uniffi = "=0.24.1"
schemars = { version = ">=0.8, <0.9", optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bitwarden::{client::client_settings::ClientSettings, mobile::crypto::InitCry
pub mod auth;
mod error;
pub mod tool;
mod uniffi_support;
pub mod vault;

#[cfg(feature = "docs")]
Expand Down
16 changes: 16 additions & 0 deletions crates/bitwarden-uniffi/src/uniffi_support.rs
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()
}
}
3 changes: 2 additions & 1 deletion crates/bitwarden-uniffi/src/vault/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use bitwarden::vault::TotpResponse;
use chrono::{DateTime, Utc};

use crate::Client;

Expand Down Expand Up @@ -46,7 +47,7 @@ impl ClientVault {
/// - A base32 encoded string
/// - OTP Auth URI
/// - Steam URI
pub async fn generate_totp(&self, key: String) -> TotpResponse {
pub async fn generate_totp(&self, key: String, time: Option<DateTime<Utc>>) -> TotpResponse {
self.0 .0.read().await.vault().generate_totp(key).await
}
}
6 changes: 4 additions & 2 deletions crates/bitwarden/src/mobile/vault/client_totp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use chrono::{DateTime, Utc};

use crate::vault::{generate_totp, TotpResponse};

use super::client_vault::ClientVault;
Expand All @@ -10,7 +12,7 @@ impl<'a> ClientVault<'a> {
/// - OTP Auth URI
/// - Steam URI
///
pub async fn generate_totp(&'a self, key: String) -> TotpResponse {
generate_totp(key).await
pub async fn generate_totp(&'a self, key: String, time: Option<DateTime<Utc>>) -> TotpResponse {
generate_totp(key, time).await
}
}
3 changes: 2 additions & 1 deletion crates/bitwarden/src/vault/totp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand All @@ -9,7 +10,7 @@ pub struct TotpResponse {
pub interval: u32,
}

pub async fn generate_totp(_key: String) -> TotpResponse {
pub async fn generate_totp(_key: String, _time: Option<DateTime<Utc>>) -> TotpResponse {
TotpResponse {
code: "000 000".to_string(),
interval: 30,
Expand Down
1 change: 1 addition & 0 deletions languages/kotlin/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ The key can be either:

- self:
- key: String
- time: Option<DateTime>

**Output**: [TotpResponse](#totpresponse)

Expand Down

0 comments on commit 35ee037

Please sign in to comment.