Add get_default_parameters & UnsupportedParametersError to API docs

This commit is contained in:
Hynek Schlawack 2025-02-22 08:45:03 +01:00
parent aa98519d64
commit fade17c9ee
No known key found for this signature in database
5 changed files with 18 additions and 15 deletions

View File

@ -14,7 +14,8 @@ If you don't specify any parameters, the following constants are used:
.. data:: DEFAULT_MEMORY_COST
.. data:: DEFAULT_PARALLELISM
They are taken from :data:`argon2.profiles.RFC_9106_LOW_MEMORY`.
They are taken from :data:`argon2.profiles.RFC_9106_LOW_MEMORY`, but they may vary depending on the platform.
You can use :func:`argon2.profiles.get_default_parameters` to get the current platform's defaults.
Profiles
@ -79,6 +80,8 @@ That should give you a feeling on how they perform in *your* environment.
.. versionadded:: 21.2.0
.. autofunction:: argon2.profiles.get_default_parameters
.. _`RFC 9106`: https://www.rfc-editor.org/rfc/rfc9106.html
@ -95,6 +98,9 @@ Exceptions
.. autoexception:: argon2.exceptions.InvalidHash
.. autoexception:: argon2.exceptions.UnsupportedParametersError
Utilities
---------

View File

@ -8,7 +8,7 @@ import sys
from dataclasses import dataclass
from typing import Any
from .exceptions import InvalidHashError, UnsupportedParamsError
from .exceptions import InvalidHashError, UnsupportedParametersError
from .low_level import Type
@ -171,4 +171,4 @@ def validate_params_for_platform(params: Parameters) -> None:
"""
if _is_wasm() and params.parallelism != 1:
msg = "In WebAssembly environments `parallelism` must be 1."
raise UnsupportedParamsError(msg)
raise UnsupportedParametersError(msg)

View File

@ -46,21 +46,15 @@ class InvalidHashError(ValueError):
"""
class UnsupportedParamsError(ValueError):
class UnsupportedParametersError(ValueError):
"""
Raised if the current platform does not support the parameters.
Raised if the current platform does not support the parameters.
For example, in WebAssembly parallelism must be set to 1.
For example, in WebAssembly parallelism must be set to 1.
.. versionadded:: 25.1.0
"""
def __init__(
self,
message: str = "Params are not compatible with the current platform",
) -> None:
super().__init__(message)
InvalidHash = InvalidHashError
"""

View File

@ -21,6 +21,9 @@ def get_default_parameters() -> Parameters:
"""
Create default parameters for current platform.
Returns:
Default, compatible, parameters for current platform.
.. versionadded:: 25.1.0
"""
params = RFC_9106_LOW_MEMORY

View File

@ -10,7 +10,7 @@ from argon2._utils import Parameters
from argon2.exceptions import (
InvalidHash,
InvalidHashError,
UnsupportedParamsError,
UnsupportedParametersError,
)
@ -167,7 +167,7 @@ class TestPasswordHasher:
for machine in ["wasm32", "wasm64"]:
with mock.patch("platform.machine", return_value=machine):
with pytest.raises(
UnsupportedParamsError,
UnsupportedParametersError,
match="In WebAssembly environments `parallelism` must be 1.",
):
PasswordHasher(parallelism=2)
@ -175,7 +175,7 @@ class TestPasswordHasher:
# last param is parallelism so it should fail
params = Parameters(Type.I, 2, 8, 8, 3, 256, 8)
with pytest.raises(
UnsupportedParamsError,
UnsupportedParametersError,
match="In WebAssembly environments `parallelism` must be 1.",
):
ph = PasswordHasher.from_parameters(params)