Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_legacy.py93 linesDownload Raw Back to argon2
1# SPDX-License-Identifier: MIT2 3"""4Legacy mid-level functions.5"""6 7from __future__ import annotations8 9import os10import warnings11 12from typing import Literal13 14from ._password_hasher import (15    DEFAULT_HASH_LENGTH,16    DEFAULT_MEMORY_COST,17    DEFAULT_PARALLELISM,18    DEFAULT_RANDOM_SALT_LENGTH,19    DEFAULT_TIME_COST,20)21from .low_level import Type, hash_secret, hash_secret_raw, verify_secret22 23 24_INSTEAD = " is deprecated, use argon2.PasswordHasher instead"25 26 27def hash_password(28    password: bytes,29    salt: bytes | None = None,30    time_cost: int = DEFAULT_TIME_COST,31    memory_cost: int = DEFAULT_MEMORY_COST,32    parallelism: int = DEFAULT_PARALLELISM,33    hash_len: int = DEFAULT_HASH_LENGTH,34    type: Type = Type.I,35) -> bytes:36    """37    Legacy alias for :func:`argon2.low_level.hash_secret` with default38    parameters.39 40    .. deprecated:: 16.0.041        Use :class:`argon2.PasswordHasher` for passwords.42    """43    warnings.warn(44        "argon2.hash_password" + _INSTEAD, DeprecationWarning, stacklevel=245    )46    if salt is None:47        salt = os.urandom(DEFAULT_RANDOM_SALT_LENGTH)48    return hash_secret(49        password, salt, time_cost, memory_cost, parallelism, hash_len, type50    )51 52 53def hash_password_raw(54    password: bytes,55    salt: bytes | None = None,56    time_cost: int = DEFAULT_TIME_COST,57    memory_cost: int = DEFAULT_MEMORY_COST,58    parallelism: int = DEFAULT_PARALLELISM,59    hash_len: int = DEFAULT_HASH_LENGTH,60    type: Type = Type.I,61) -> bytes:62    """63    Legacy alias for :func:`argon2.low_level.hash_secret_raw` with default64    parameters.65 66    .. deprecated:: 16.0.067        Use :class:`argon2.PasswordHasher` for passwords.68    """69    warnings.warn(70        "argon2.hash_password_raw" + _INSTEAD, DeprecationWarning, stacklevel=271    )72    if salt is None:73        salt = os.urandom(DEFAULT_RANDOM_SALT_LENGTH)74    return hash_secret_raw(75        password, salt, time_cost, memory_cost, parallelism, hash_len, type76    )77 78 79def verify_password(80    hash: bytes, password: bytes, type: Type = Type.I81) -> Literal[True]:82    """83    Legacy alias for :func:`argon2.low_level.verify_secret` with default84    parameters.85 86    .. deprecated:: 16.0.087        Use :class:`argon2.PasswordHasher` for passwords.88    """89    warnings.warn(90        "argon2.verify_password" + _INSTEAD, DeprecationWarning, stacklevel=291    )92    return verify_secret(hash, password, type)93 
codekingpro/portable-devtools · Team Ai