Apply suggestions from code review

Co-authored-by: str4d <thestr4d@gmail.com>
This commit is contained in:
Kan-Ru Chen 2021-01-15 22:29:13 +09:00 committed by GitHub
parent 4a04e61b07
commit 13aeae847d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View file

@ -41,8 +41,11 @@ See the [documentation](https://docs.rs/age) for examples.
- `ssh` enables the `age::ssh` module, which allows for reusing existing SSH key
files for age encryption.
- `web-sys` enables calculating scrypt work factor with web Performance timer when
compiled to WebAssembly via the `web-sys` crate.
- `web-sys` enables calculating the work factor for passphrase encryption with the
[Performance timer](https://developer.mozilla.org/en-US/docs/Web/API/Performance)
via the `web-sys` crate, when compiling for a WebAssembly target such as
`wasm32-unknown-unknown`. This feature is ignored for the `wasm32-wasi` target,
which supports [`std::time::SystemTime`](https://doc.rust-lang.org/stable/std/time/struct.SystemTime.html#underlying-system-calls).
- `unstable` enables in-development functionality. Anything behind this feature
flag has no stability or interoperability guarantees.
@ -63,4 +66,3 @@ Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.

View file

@ -39,7 +39,11 @@ fn target_scrypt_work_factor() -> u8 {
}
// Platforms that can use Performance timer
#[cfg(all(target_arch = "wasm32", feature = "web-sys"))]
#[cfg(all(
target_arch = "wasm32",
not(target_os = "wasi"),
feature = "web-sys"
))]
{
web_sys::window().and_then(|window| {
{ window.performance() }.map(|performance| {
@ -53,8 +57,8 @@ fn target_scrypt_work_factor() -> u8 {
// Platforms where SystemTime::now() panics:
#[cfg(all(
target_arch = "wasm32",
not(feature = "web-sys"),
not(target_os = "wasi")
not(target_os = "wasi"),
not(feature = "web-sys")
))]
{
None