FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
examples/spawn-blocking/src/tests.rs at master · ProgrammingRust/examples · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ProgrammingRust
/
examples
Public
Notifications
You must be signed in to change notification settings
Fork
260
Star
1.2k
Code
Issues
4
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
examples
/
spawn-blocking
/
src
/
tests.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (48 loc) · 1.46 KB
Breadcrumbs
examples
/
spawn-blocking
/
src
/
tests.rs
Copy path
File metadata and controls
55 lines (48 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use
super
::
*
;
async
fn
verify_password
(
password
:
&
str
,
hash
:
&
str
,
key
:
&
str
)
->
Result
<
bool
,
argonautica
::
Error
>
{
let
password = password
.
to_string
(
)
;
let
hash = hash
.
to_string
(
)
;
let
key = key
.
to_string
(
)
;
spawn_blocking
(
move
||
{
argonautica
::
Verifier
::
default
(
)
.
with_hash
(
hash
)
.
with_password
(
password
)
.
with_secret_key
(
key
)
.
verify
(
)
}
)
.
await
}
static
PASSWORD
:
&
str
=
"P@ssw0rd"
;
static
HASH
:
&
str
=
"$argon2id$v=19$m=4096,t=192,p=4$
\
o2y5PU86Vt+sr93N7YUGgC7AMpTKpTQCk4tNGUPZMY4$
\
yzP/ukZRPIbZg6PvgnUUobUMbApfF9RH6NagL9L4Xr4
\
"
;
static
SECRET_KEY
:
&
str
=
"secret key that you should really store in a .env file
\
instead of in code, but this is just an example
\
"
;
#
[
test
]
fn
argonautica
(
)
{
async_std
::
task
::
block_on
(
async
{
assert
!
(
verify_password
(
PASSWORD
,
HASH
,
SECRET_KEY
)
.
await
.
unwrap
(
)
)
;
}
)
;
}
#
[
test
]
fn
many_serial
(
)
{
async_std
::
task
::
block_on
(
async
{
for
i
in
0
..
1000
{
assert_eq
!
(
spawn_blocking
(
move || i
)
.
await
,
i
)
;
}
}
)
;
}
#
[
test
]
fn
many_parallel
(
)
{
async_std
::
task
::
block_on
(
async
{
let
futures
:
Vec
<
_
>
=
(
0
..
100
)
.
map
(
|i|
(
i
,
spawn_blocking
(
move
|| i
)
)
)
.
collect
(
)
;
for
(
i
,
f
)
in
futures
{
assert_eq
!
(
f
.
await
,
i
)
;
}
}
)
;
}
Back
|
FazBrowse Home
|
New Git URL