Skip to content

Commit 259dbfd

Browse files
committed
feat: Simplify Timestamp handling for WASM and non-WASM targets
1 parent d588798 commit 259dbfd

File tree

3 files changed

+4
-33
lines changed

3 files changed

+4
-33
lines changed

crypto-ffi/src/identity/x509.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#[cfg(target_family = "wasm")]
2-
use std::time::{Duration, SystemTime};
3-
4-
#[cfg(not(target_family = "wasm"))]
51
use crate::Timestamp;
62

73
/// Represents the parts of [WireIdentity][crate::WireIdentity] that are specific to a X509 certificate (and not a Basic
@@ -23,40 +19,22 @@ pub struct X509Identity {
2319
pub serial_number: String,
2420

2521
/// X509 certificate not before
26-
#[cfg(not(target_family = "wasm"))]
2722
pub not_before: Timestamp,
28-
/// X509 certificate not before
29-
#[cfg(target_family = "wasm")]
30-
pub not_before: SystemTime,
3123

3224
/// X509 certificate not after
33-
#[cfg(not(target_family = "wasm"))]
3425
pub not_after: Timestamp,
35-
/// X509 certificate not after
36-
#[cfg(target_family = "wasm")]
37-
pub not_after: SystemTime,
3826
}
3927

4028
impl From<core_crypto::X509Identity> for X509Identity {
4129
fn from(i: core_crypto::X509Identity) -> Self {
42-
#[cfg(not(target_family = "wasm"))]
43-
let not_before = Timestamp::from_epoch_secs(i.not_before);
44-
#[cfg(target_family = "wasm")]
45-
let not_before = SystemTime::UNIX_EPOCH + Duration::from_secs(i.not_before);
46-
47-
#[cfg(not(target_family = "wasm"))]
48-
let not_after = Timestamp::from_epoch_secs(i.not_after);
49-
#[cfg(target_family = "wasm")]
50-
let not_after = SystemTime::UNIX_EPOCH + Duration::from_secs(i.not_after);
51-
5230
Self {
5331
handle: i.handle,
5432
display_name: i.display_name,
5533
domain: i.domain,
5634
certificate: i.certificate,
5735
serial_number: i.serial_number,
58-
not_before,
59-
not_after,
36+
not_before: Timestamp::from_epoch_secs(i.not_before),
37+
not_after: Timestamp::from_epoch_secs(i.not_after),
6038
}
6139
}
6240
}

crypto-ffi/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ mod key_package;
2929
mod metadata;
3030
mod proteus;
3131
mod signature_scheme;
32-
#[cfg(not(target_family = "wasm"))]
3332
mod timestamp;
3433

3534
pub use bundles::{
@@ -76,5 +75,4 @@ pub use identity::{
7675
pub use key_package::{Keypackage, KeypackageRef};
7776
pub use metadata::{BuildMetadata, build_metadata, version};
7877
pub use signature_scheme::SignatureScheme;
79-
#[cfg(not(target_family = "wasm"))]
8078
pub use timestamp::Timestamp;

crypto-ffi/src/timestamp.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
//! This wrapper allows custom type mapping per target language:
44
//! - Kotlin: maps to `kotlinx.datetime.Instant`
55
//! - Swift: maps to `Date`
6+
//! - WASM/JS: maps to `Date` (via uniffi-bindgen-react-native)
67
//!
7-
//! This unifies timestamp handling across JVM/Android and KMP bindings.
8+
//! This unifies timestamp handling across JVM/Android, KMP.
89
//! This can be removed once we fully migrate to Kotlin Multiplatform and
910
//! stop generating JVM/Android bindings.
1011
11-
#[cfg(not(target_family = "wasm"))]
1212
use std::time::{Duration, SystemTime};
1313

1414
/// A wrapper around `SystemTime` for FFI bindings with custom type mapping per language.
15-
#[cfg(not(target_family = "wasm"))]
1615
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
1716
pub struct Timestamp(pub SystemTime);
1817

19-
#[cfg(not(target_family = "wasm"))]
2018
impl Timestamp {
2119
/// Creates a new `Timestamp` from a `SystemTime`.
2220
pub fn new(time: SystemTime) -> Self {
@@ -34,19 +32,16 @@ impl Timestamp {
3432
}
3533
}
3634

37-
#[cfg(not(target_family = "wasm"))]
3835
impl From<SystemTime> for Timestamp {
3936
fn from(time: SystemTime) -> Self {
4037
Self(time)
4138
}
4239
}
4340

44-
#[cfg(not(target_family = "wasm"))]
4541
impl From<Timestamp> for SystemTime {
4642
fn from(timestamp: Timestamp) -> Self {
4743
timestamp.0
4844
}
4945
}
5046

51-
#[cfg(not(target_family = "wasm"))]
5247
uniffi::custom_type!(Timestamp, SystemTime);

0 commit comments

Comments
 (0)