-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for wasm32-pyodide #190
Merged
Merged
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1c95d7e
Added support for wasm32-pyodide
alarmfox 4099d53
Removed match: not supported before python 3.10
alarmfox 8f15021
Added test with good case
alarmfox 2a721f8
Changed default parallelism=1 when platform.machine() = wasm32
alarmfox e1694cc
More robust platform checking
alarmfox fd48f0a
Testing under different platforms
alarmfox d3b6ecc
Added error message to UnsupportedParamsError
alarmfox 25ca6f7
Added centralized functions for parameters validations and platform-c…
alarmfox 23bb82b
Pre-commit
alarmfox a621190
Added test for PasswordHasher.from_parameters()
alarmfox 5650323
Pre commit
alarmfox fb75e7d
Fix pre-commit
alarmfox fb5d68f
Fix test: made PasswordHasher.from_parameters easier to test
alarmfox d164813
Update src/argon2/exceptions.py
alarmfox 79940f2
Merge branch 'hynek:main' into main
alarmfox b708393
Update tests/test_password_hasher.py
hynek da5c562
Update src/argon2/_password_hasher.py
hynek 9f94cca
Update .python-version-default
hynek 3697d8b
Update tests/test_password_hasher.py
hynek 1e612bc
Update tests/test_password_hasher.py
hynek d89221f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e85cc2d
Update src/argon2/profiles.py
hynek 8cdc6d9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 622df98
Update src/argon2/_utils.py
hynek cfd873d
Update src/argon2/exceptions.py
hynek 1959092
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8361abc
Update tests/test_password_hasher.py
hynek c341964
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 86e2b27
Update tests/test_password_hasher.py
hynek bf70b4b
Update tests/test_password_hasher.py
hynek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from argon2 import PasswordHasher, Type, extract_parameters, profiles | ||
from argon2._password_hasher import _ensure_bytes | ||
from argon2.exceptions import InvalidHash, InvalidHashError | ||
from argon2._utils import Parameters | ||
from argon2.exceptions import ( | ||
InvalidHash, | ||
InvalidHashError, | ||
UnsupportedParamsError, | ||
) | ||
|
||
|
||
class TestEnsureBytes: | ||
|
@@ -151,3 +158,41 @@ def test_type_is_configurable(self): | |
assert Type.I is ph.type is ph._parameters.type | ||
assert Type.I is extract_parameters(ph.hash("foo")).type | ||
assert ph.check_needs_rehash(default_hash) | ||
|
||
@mock.patch("sys.platform", "emscripten") | ||
def test_params_on_wasm(self): | ||
""" | ||
Should fail if on wasm and parallelism > 1 | ||
""" | ||
for machine in ["wasm32", "wasm64"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's make this a parametrization |
||
with mock.patch("platform.machine", return_value=machine): | ||
with pytest.raises(UnsupportedParamsError) as exinfo: | ||
PasswordHasher(parallelism=2) | ||
|
||
assert ( | ||
str(exinfo.value) | ||
== "within wasm/wasi environments `parallelism` must be set to 1" | ||
) | ||
hynek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# last param is parallelism so it should fail | ||
params = Parameters(Type.I, 2, 8, 8, 3, 256, 8) | ||
with pytest.raises( | ||
UnsupportedParamsError, | ||
match="In WebAssembly environments `parallelism` must be 1.", | ||
) as exinfo: | ||
hynek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ph = PasswordHasher.from_parameters(params) | ||
|
||
# explicitly correct parameters | ||
ph = PasswordHasher(parallelism=1) | ||
|
||
hash = ph.hash("hello") | ||
|
||
assert ph.verify(hash, "hello") is True | ||
|
||
# explicit, but still default parameters | ||
default_params = profiles.get_default_params() | ||
ph = PasswordHasher.from_parameters(default_params) | ||
|
||
hash = ph.hash("hello") | ||
|
||
assert ph.verify(hash, "hello") is True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class needs to be added to the API docs.