diff options
author | Steve Dignam <sbdchd@users.noreply.github.com> | 2020-08-13 22:09:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-13 21:09:30 -0500 |
commit | f9066e2be5881a39f0048a86987728df4fd9f773 (patch) | |
tree | fe2569b54e3baa1ce79fee15f3c1fe6db33ad0bc /src/bcrypt | |
parent | f3c255ca158182d024fa02e358e45a886886c2e7 (diff) | |
download | py-bcrypt-git-f9066e2be5881a39f0048a86987728df4fd9f773.tar.gz |
add: type hints to top level functions (#218)
* WIP: add type hints to top level functions
TODO:
- see if mypy picks up types when installing in new project
- setup mypy in CI
fixes https://github.com/pyca/bcrypt/issues/215
* add mypy to ci & move py.typed to correct folder?
* try and get mypy to run in CI
* run mypy in travis?
* use mypy defaults for python_version and platform
https://mypy.readthedocs.io/en/stable/config_file.html#platform-configuration
* update change log with changes
Diffstat (limited to 'src/bcrypt')
-rw-r--r-- | src/bcrypt/__init__.py | 18 | ||||
-rw-r--r-- | src/bcrypt/py.typed | 0 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/bcrypt/__init__.py b/src/bcrypt/__init__.py index 9679a42..0a8cc05 100644 --- a/src/bcrypt/__init__.py +++ b/src/bcrypt/__init__.py @@ -22,7 +22,7 @@ import warnings import six -from . import _bcrypt +from . import _bcrypt # type: ignore from .__about__ import ( __author__, __copyright__, @@ -54,7 +54,7 @@ __all__ = [ _normalize_re = re.compile(br"^\$2y\$") -def gensalt(rounds=12, prefix=b"2b"): +def gensalt(rounds: int = 12, prefix: bytes = b"2b") -> bytes: if prefix not in (b"2a", b"2b"): raise ValueError("Supported prefixes are b'2a' or b'2b'") @@ -75,7 +75,7 @@ def gensalt(rounds=12, prefix=b"2b"): ) -def hashpw(password, salt): +def hashpw(password: bytes, salt: bytes) -> bytes: if isinstance(password, six.text_type) or isinstance(salt, six.text_type): raise TypeError("Unicode-objects must be encoded before hashing") @@ -113,7 +113,7 @@ def hashpw(password, salt): return original_salt[:4] + _bcrypt.ffi.string(hashed)[4:] -def checkpw(password, hashed_password): +def checkpw(password: bytes, hashed_password: bytes) -> bool: if isinstance(password, six.text_type) or isinstance( hashed_password, six.text_type ): @@ -132,7 +132,13 @@ def checkpw(password, hashed_password): return _bcrypt.lib.timingsafe_bcmp(ret, hashed_password, len(ret)) == 0 -def kdf(password, salt, desired_key_bytes, rounds, ignore_few_rounds=False): +def kdf( + password: bytes, + salt: bytes, + desired_key_bytes: int, + rounds: int, + ignore_few_rounds: bool = False, +) -> bytes: if isinstance(password, six.text_type) or isinstance(salt, six.text_type): raise TypeError("Unicode-objects must be encoded before hashing") @@ -167,6 +173,6 @@ def kdf(password, salt, desired_key_bytes, rounds, ignore_few_rounds=False): return _bcrypt.ffi.buffer(key, desired_key_bytes)[:] -def _bcrypt_assert(ok): +def _bcrypt_assert(ok: bool) -> None: if not ok: raise SystemError("bcrypt assertion failed") diff --git a/src/bcrypt/py.typed b/src/bcrypt/py.typed new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/bcrypt/py.typed |