File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -15,12 +15,19 @@ rust-version = "1.67.0"
15
15
[dependencies ]
16
16
serde_json = " 1.0"
17
17
serde = {version = " 1.0" , features = [" derive" ] }
18
- ring = { version = " 0.17.4" , features = [" std" ] }
19
18
base64 = " 0.21.0"
20
19
# For PEM decoding
21
20
pem = {version = " 3" , optional = true }
22
21
simple_asn1 = {version = " 0.6" , optional = true }
23
22
23
+ [target .'cfg(not(target_arch = "wasm32"))' .dependencies ]
24
+ ring = { version = " 0.17.4" , features = [" std" ] }
25
+
26
+
27
+ [target .'cfg(target_arch = "wasm32")' .dependencies ]
28
+ js-sys = " 0.3"
29
+ ring = { version = " 0.17.4" , features = [" std" , " wasm32_unknown_unknown_js" ] }
30
+
24
31
[dev-dependencies ]
25
32
# For the custom time example
26
33
time = " 0.3"
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ use std::borrow::Cow;
2
2
use std:: collections:: HashSet ;
3
3
use std:: fmt;
4
4
use std:: marker:: PhantomData ;
5
- use std:: time:: { SystemTime , UNIX_EPOCH } ;
6
5
7
6
use serde:: de:: { self , Visitor } ;
8
7
use serde:: { Deserialize , Deserializer } ;
@@ -137,9 +136,18 @@ impl Default for Validation {
137
136
}
138
137
139
138
/// Gets the current timestamp in the format expected by JWTs.
139
+ #[ cfg( not( all( target_arch = "wasm32" , not( any( target_os = "emscripten" , target_os = "wasi" ) ) ) ) ) ]
140
+ #[ must_use]
140
141
pub fn get_current_timestamp ( ) -> u64 {
141
- let start = SystemTime :: now ( ) ;
142
- start. duration_since ( UNIX_EPOCH ) . expect ( "Time went backwards" ) . as_secs ( )
142
+ let start = std:: time:: SystemTime :: now ( ) ;
143
+ start. duration_since ( std:: time:: UNIX_EPOCH ) . expect ( "Time went backwards" ) . as_secs ( )
144
+ }
145
+
146
+ /// Gets the current timestamp in the format expected by JWTs.
147
+ #[ cfg( all( target_arch = "wasm32" , not( any( target_os = "emscripten" , target_os = "wasi" ) ) ) ) ]
148
+ #[ must_use]
149
+ pub fn get_current_timestamp ( ) -> u64 {
150
+ js_sys:: Date :: new_0 ( ) . get_time ( ) as u64 / 1000
143
151
}
144
152
145
153
#[ derive( Deserialize ) ]
You can’t perform that action at this time.
0 commit comments