Skip to content

Commit

Permalink
docs: fix nitpicky build
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Aug 15, 2023
1 parent 18339bd commit a1d48eb
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 60 deletions.
17 changes: 13 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,23 @@ At this point,
$ python -m pytest
```

should work and pass, as should:
should work and pass.

For documentation, you can use:

```console
$ tox run -e docs-watch
```

This will build the documentation, and then watch for changes and rebuild it whenever you save a file.

To just build the documentation and run doctests, use:

```console
$ cd docs
$ make html
$ tox run -e docs
```

The built documentation can then be found in `docs/_build/html/`.
You will find the built documentation in `docs/_build/html`.

To avoid committing code that violates our style guide, we strongly advise you to install [*pre-commit*] and its hooks:

Expand Down
6 changes: 5 additions & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## Supported Versions

We are following [CalVer](https://calver.org) with generous backward-compatibility guarantees. Therefore we only support the latest version.
We follow [CalVer](https://calver.org) with generous backwards-compatibility guarantees.
Therefore, we only support the latest version.

That said, you shouldn't be afraid to upgrade if you're only using our documented public APIs and pay attention to `DeprecationWarning`s.
Whenever there is a need to break compatibility, it is announced in the changelog and raises a `DeprecationWarning` for a year (if possible) before it's finally really broken.


## Security contact information
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- begin-short -->

[Argon2](https://github.com/p-h-c/phc-winner-argon2) won the [Password Hashing Competition](https://www.password-hashing.net/) and *argon2-cffi* is the simplest way to use it in Python and PyPy:
[Argon2](https://github.com/p-h-c/phc-winner-argon2) won the [Password Hashing Competition](https://www.password-hashing.net/) and *argon2-cffi* is the simplest way to use it in Python:

```pycon
>>> from argon2 import PasswordHasher
Expand All @@ -29,17 +29,16 @@ argon2.exceptions.VerifyMismatchError: The password does not match the supplied
```
<!-- end-short -->

## Project Information
## Project Links

- [**PyPI**](https://pypi.org/project/argon2-cffi/)
- [**Source Code**](https://github.com/hynek/argon2-cffi)
- [**GitHub**](https://github.com/hynek/argon2-cffi)
- [**Documentation**](https://argon2-cffi.readthedocs.io/)
- [**Changelog**](https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md)
- The low-level Argon2 CFFI bindings are maintained in the separate [*argon2-cffi-bindings*](https://github.com/hynek/argon2-cffi-bindings) project.

The low-level Argon2 CFFI bindings are maintained in the separate [*argon2-cffi-bindings*](https://github.com/hynek/argon2-cffi-bindings) project.


### Credits
## Credits

*argon2-cffi* is maintained by [Hynek Schlawack](https://hynek.me/).

Expand All @@ -48,7 +47,7 @@ The development is kindly supported by my employer [Variomedia AG](https://www.v
A full list of contributors can be found in GitHub's [overview](https://github.com/hynek/argon2-cffi/graphs/contributors).


### *argon2-cffi* for Enterprise
## *argon2-cffi* for Enterprise

Available as part of the Tidelift Subscription.

Expand Down
17 changes: 16 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,22 @@ Low Level
.. automodule:: argon2.low_level

.. autoclass:: Type
:members: D, I, ID

.. attribute:: D

Argon2\ **d** is faster and uses data-depending memory access.
That makes it less suitable for hashing secrets and more suitable for cryptocurrencies and applications with no threats from side-channel timing attacks.

.. attribute:: I

Argon2\ **i** uses data-independent memory access.
Argon2i is slower as it makes more passes over the memory to protect from tradeoff attacks.

.. attribute:: ID

Argon2\ **id** is a hybrid of Argon2i and Argon2d, using a combination of data-depending and data-independent memory accesses, which gives some of Argon2i's resistance to side-channel cache timing attacks and much of Argon2d's resistance to GPU cracking attacks.

.. versionadded:: 16.3.0

.. autodata:: ARGON2_VERSION

Expand Down
2 changes: 0 additions & 2 deletions docs/changelog.md

This file was deleted.

2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
# directories to ignore when looking for source files.
exclude_patterns = ["_build"]

nitpick_ignore = []

# The reST default role (used for this markup: `text`) to use for all
# documents.
default_role = "any"
Expand Down
19 changes: 15 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# *argon2-cffi*: Argon2 for Python

Release **{sub-ref}`release`** ([What's new?](changelog))
Release **{sub-ref}`release`** ([What's new?](https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md))

```{include} ../README.md
:end-before: <!-- end-short -->
Expand All @@ -19,18 +19,29 @@ api
parameters
cli
faq
changelog
```


## Project Information
## Project Links

```{include} ../README.md
:start-after: '## Project Information'
:start-after: '## Project Links'
```


## Indices and tables

- {ref}`genindex`
- {ref}`search`

```{toctree}
:hidden:
:caption: Meta
PyPI <https://pypi.org/project/argon2-cffi/>
GitHub <https://github.com/hynek/argon2-cffi/>
Changelog <https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md>
Contributing <https://github.com/hynek/argon2-cffi/blob/main/.github/CONTRIBUTING.md>
Security Policy <https://github.com/hynek/argon2-cffi/blob/main/.github/SECURITY.md>
Funding <https://hynek.me/say-thanks/>
```
4 changes: 2 additions & 2 deletions docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ It comes with two recommendations in [section 4](https://www.rfc-editor.org/rfc/

Please use the {doc}`cli` interface together with its `--profile` argument to see if they work for you.

______________________________________________________________________
---

If you need finer tuning, the current recommended best practice is as follow:

1. Choose whether you want Argon2i, Argon2d, or Argon2id (`type`).
If you don't know what that means, choose Argon2id ({attr}`argon2.Type.ID`).
If you don't know what that means, choose Argon2id ({attr}`argon2.low_level.Type.ID`).

2. Figure out how many threads can be used on each call to Argon2 (`parallelism`, called "lanes" in the RFC).
They recommend 4 threads.
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ dependencies = [
[project.optional-dependencies]
tests = ["hypothesis", "pytest"]
docs = ["sphinx", "sphinx-notfound-page", "furo", "myst-parser"]
dev = ["argon2-cffi[tests,docs]", "mypy"]
dev = ["argon2-cffi[tests]", "mypy"]

[project.urls]
Documentation = "https://argon2-cffi.readthedocs.io/"
Changelog = "https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md"
"Source Code" = "https://github.com/hynek/argon2-cffi"
GitHub = "https://github.com/hynek/argon2-cffi"
Funding = "https://github.com/sponsors/hynek"
Tidelift = "https://tidelift.com/subscription/pkg/pypi-argon2-cffi?utm_source=pypi-argon2-cffi&utm_medium=pypi"

Expand Down
13 changes: 13 additions & 0 deletions src/argon2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,16 @@ def __getattr__(name: str) -> str:
return meta["Author-email"].split("<", 1)[1].rstrip(">")

return meta[dunder_to_metadata[name]]


# Make nicer public names.
__locals = locals()
for __name in __all__:
if (
not isinstance(__locals[__name], int)
and not __name.startswith("__")
and not __name.islower()
):
__locals[__name].__module__ = "argon2"
del __locals
del __name # pyright: ignore[reportUnboundVariable]
9 changes: 6 additions & 3 deletions src/argon2/_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def hash_password(
type: Type = Type.I,
) -> bytes:
"""
Legacy alias for :func:`hash_secret` with default parameters.
Legacy alias for :func:`argon2.low_level.hash_secret` with default
parameters.
.. deprecated:: 16.0.0
Use :class:`argon2.PasswordHasher` for passwords.
Expand All @@ -51,7 +52,8 @@ def hash_password_raw(
type: Type = Type.I,
) -> bytes:
"""
Legacy alias for :func:`hash_secret_raw` with default parameters.
Legacy alias for :func:`argon2.low_level.hash_secret_raw` with default
parameters.
.. deprecated:: 16.0.0
Use :class:`argon2.PasswordHasher` for passwords.
Expand All @@ -67,7 +69,8 @@ def verify_password(
hash: bytes, password: bytes, type: Type = Type.I
) -> Literal[True]:
"""
Legacy alias for :func:`verify_secret` with default parameters.
Legacy alias for :func:`argon2.low_level.verify_secret` with default
parameters.
.. deprecated:: 16.0.0
Use :class:`argon2.PasswordHasher` for passwords.
Expand Down
2 changes: 1 addition & 1 deletion src/argon2/_password_hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def verify(
because *hash* is not valid for *password*.
:raises argon2.exceptions.VerificationError: If verification fails for
other reasons.
:raises argon2.exceptions.InvalidHash: If *hash* is so clearly
:raises argon2.exceptions.InvalidHashError: If *hash* is so clearly
invalid, that it couldn't be passed to Argon2.
:return: ``True`` on success, raise
Expand Down
23 changes: 2 additions & 21 deletions src/argon2/low_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,8 @@ class Type(Enum):
"""

D = lib.Argon2_d
r"""
Argon2\ **d** is faster and uses data-depending memory access, which makes
it less suitable for hashing secrets and more suitable for cryptocurrencies
and applications with no threats from side-channel timing attacks.
"""
I = lib.Argon2_i # noqa: E741
r"""
Argon2\ **i** uses data-independent memory access. Argon2i is slower as
it makes more passes over the memory to protect from tradeoff attacks.
"""
ID = lib.Argon2_id
r"""
Argon2\ **id** is a hybrid of Argon2i and Argon2d, using a combination of
data-depending and data-independent memory accesses, which gives some of
Argon2i's resistance to side-channel cache timing attacks and much of
Argon2d's resistance to GPU cracking attacks.
That makes it the preferred type for password hashing and password-based
key derivation.
.. versionadded:: 16.3.0
"""


def hash_secret(
Expand All @@ -92,7 +72,8 @@ def hash_secret(
:param Type type: Which Argon2 variant to use.
:param int version: Which Argon2 version to use.
For an explanation of the Argon2 parameters see :class:`PasswordHasher`.
For an explanation of the Argon2 parameters see
:class:`argon2.PasswordHasher`.
:rtype: bytes
Expand Down
2 changes: 1 addition & 1 deletion src/argon2/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""
This module offers access to standardized parameters that you can load using
:meth:`PasswordHasher.from_parameters()`. See the `source code
:meth:`argon2.PasswordHasher.from_parameters()`. See the `source code
<https://github.com/hynek/argon2-cffi/blob/main/src/argon2/profiles.py>`_ for
concrete values and :doc:`parameters` for more information.
Expand Down
41 changes: 30 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ install_command = pip install {opts} --no-deps {packages}
commands_pre = pip install -I hypothesis pytest git+https://github.com/hynek/argon2-cffi-bindings


[testenv:docs]
description = Build docs and run doctests.
# Keep base_python in-sync with .readthedocs.yaml and ci.yml/docs.
base_python = py311
extras = docs
commands =
python -Im doctest README.md
sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html
sphinx-build -W -b doctest -d {envtmpdir}/doctrees docs docs/_build/html


[testenv:pre-commit]
description = Run all pre-commit hooks.
skip_install = true
Expand All @@ -86,3 +75,33 @@ commands = mypy src
description = Check only API types.
deps = mypy
commands = mypy tests/typing


[testenv:docs]
description = Build docs and run doctests.
# Keep base_python in-sync with .readthedocs.yaml and ci.yml/docs.
base_python = py311
extras = docs
commands =
python -Im doctest README.md
sphinx-build -W -n -b html -d {envtmpdir}/doctrees docs docs/_build/html
sphinx-build -W -n -b doctest -d {envtmpdir}/doctrees docs docs/_build/html

[testenv:docs-watch]
package = editable
base_python = {[testenv:docs]base_python}
extras = {[testenv:docs]extras}
deps = watchfiles
commands =
watchfiles \
--ignore-paths docs/_build/ \
'sphinx-build -W -n --jobs auto -b html -d {envtmpdir}/doctrees docs docs/_build/html' \
src \
docs \
README.md \
CHANGELOG.md

[testenv:docs-linkcheck]
base_python = {[testenv:docs]base_python}
extras = {[testenv:docs]extras}
commands = sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees docs docs/_build/html

0 comments on commit a1d48eb

Please sign in to comment.