From 9ba69a51d1624e89d45504e1a8f23dd05810bd0e Mon Sep 17 00:00:00 2001 From: Yozachar <38415384+yozachar@users.noreply.github.com> Date: Mon, 8 Jul 2024 17:43:57 +0530 Subject: [PATCH 1/3] chore: improve `CONTRIBUTING.md` --- CONTRIBUTING.md | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ba9b1d11..8999b156 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,14 +1,14 @@ -# How to contribute to `validators` +# Contributing to `validators` Hi, to start, you need the following installed on your system. 1. [Git](https://git-scm.com) 2. [Python](https://www.python.org) v3.8 or later 3. [PDM](https://pdm-project.org) for easy dependency management -4. (Optional/Recommended) NodeJS for type checking -5. (Optional/Recommended) [mise](https://github.com/jdx/mise) to manage multiple versions of Python & NodeJS. +4. (Optional/Recommended) [`NodeJS`](https://nodejs.org/en) for type checking +5. (Optional/Recommended) [`mise`](https://github.com/jdx/mise) to manage multiple versions of Python, NodeJS and other such tools. -First [fork this repository](https://github.com/python-validators/validators/fork). Uncheck "fork only `master`", because for versioned docs you'll need `gh-pages` too. Clone it to your system. Install development dependencies. +First [fork this repository](https://github.com/python-validators/validators/fork). (If you are or intend to be a collaborator, uncheck "fork only `master`", because for versioned docs you'll need `gh-pages` branch too.) Clone it to your system and install the development dependencies. ```sh # clone repository @@ -63,8 +63,10 @@ $ python -m http.server -d docs/_build/web > You must be familiar with [semantic versioning](https://semver.org) and [Python packaging](https://packaging.python.org). -1. Take a look at the [`CHANGES.md`](CHANGES.md). They are generated with [GitHub's releaser](https://github.com/python-validators/validators/releases/new), and then modified. -2. Update the changelog. Version number must be updated in both [`SECURITY.md`](SECURITY.md) and [`src/validators/__init__.py`](src/validators/__init__.py). +### Tagging + +1. Take a look at [`CHANGES.md`](CHANGES.md). They are generated with [GitHub's releaser](https://github.com/python-validators/validators/releases/new), and then modified to fit the shown style. +2. Update the [changelog](CHANGES.md). Version number must be updated in both [`SECURITY.md`](SECURITY.md) and [`src/validators/__init__.py`](src/validators/__init__.py). 3. The final merge commit on the upstream (i.e. this repo) is tagged. ```sh @@ -72,18 +74,24 @@ $ python -m http.server -d docs/_build/web $ git pull upstream master $ git push # tagging that final merge commit before release - $ GIT_COMMITTER_DATE=$(git log -n1 --pretty=%aD) git tag -a -m "vMAJOR.MINOR.PATCH" vMAJOR.MINOR.PATCH + $ GIT_COMMITTER_DATE=$(git log -n1 --pretty=%aD) git tag -a -m "vMAJOR.MINOR.PATCH" MAJOR.MINOR.PATCH # pushing tag to remote $ git push --tag $ git push upstream --tag ``` -4. To preview versioned docs, run `mike serve` (`mike` is already a dev dependency). -5. To update it, checkout to the tag you want to include in the versioned documentation `git checkout TAG_NAME`. -6. Then run `mike deploy -p -u VERSION stable` OR run `mike deploy -p -u dev master`, -7. Which will deploy docs in the CURRENT commit as the `latest` documentation, onto `gh-pages` branch. -8. Run `./package/roll.sh` (or `./package/roll.ps1`) to generate both `sdist` and `bdist`. -9. Install [`twine`](https://pypi.org/project/twine) using [`pipx`](https://pipx.pypa.io) to upload package to PyPI. +### Versioned documentation + +1. To preview versioned docs, run `mike serve` (`mike` is a dev dependency). +2. Then (look at ) + - to publish stable docs run `mike deploy -p -u VERSION stable` after checking out to a stable tag name like `0.28.3` (note: document `VERSION = 0.29 if tag_name == 0.29.1`). + - to publish bleeding-edge docs run `mike deploy -p -u dev master` after checking out to the `master` branch. +3. This will deploy docs to the `gh-pages` branch (see: ) + +### Packaging and releasing + +1. Run `./package/roll.sh` (or `./package/roll.ps1`) to generate both `sdist` and `bdist`. +2. Install [`twine`](https://pypi.org/project/twine) using [`pipx`](https://pipx.pypa.io) to upload package to PyPI. ```sh # publishing @@ -91,11 +99,13 @@ $ python -m http.server -d docs/_build/web $ twine upload dist/* ``` -10. Create a GitHub release with the contents from the [changelog](CHANGES.md). Upload the wheel from `dist/` along with the shasum file generated with: +3. Create a GitHub release with the contents from the [changelog](CHANGES.md). Upload the wheel from `dist/` along with the shasum file generated with: ```sh # generate sha256sum $ sha256sum dist/validators-VERSION-py3-none-any.whl > dist/validators-VERSION-py3-none-any.whl.sha256 ``` -Thanks for taking interest in this library! +--- + +Thank your for taking interest in this library! From bae643fc7e06a5ccf7837ebd582747eb441dd28e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2024 17:59:13 +0530 Subject: [PATCH 2/3] chore(deps): bump certifi from 2024.6.2 to 2024.7.4 in /package (#385) Bumps [certifi](https://github.com/certifi/python-certifi) from 2024.6.2 to 2024.7.4. - [Commits](https://github.com/certifi/python-certifi/compare/2024.06.02...2024.07.04) --- updated-dependencies: - dependency-name: certifi dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package/requirements.sphinx.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/requirements.sphinx.txt b/package/requirements.sphinx.txt index 42b17cff..0237390b 100644 --- a/package/requirements.sphinx.txt +++ b/package/requirements.sphinx.txt @@ -10,9 +10,9 @@ babel==2.15.0 \ beautifulsoup4==4.12.3 \ --hash=sha256:74e3d1928edc070d21748185c46e3fb33490f22f52a3addee9aee0f4f7781051 \ --hash=sha256:b80878c9f40111313e55da8ba20bdba06d8fa3969fc68304167741bbf9e082ed -certifi==2024.6.2 \ - --hash=sha256:3cd43f1c6fa7dedc5899d69d3ad0398fd018ad1a17fba83ddaf78aa46c747516 \ - --hash=sha256:ddc6c8ce995e6987e7faf5e3f1b02b302836a0e5d98ece18392cb1a36c72ad56 +certifi==2024.7.4 \ + --hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \ + --hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90 charset-normalizer==3.3.2 \ --hash=sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027 \ --hash=sha256:06a81e93cd441c56a9b65d8e1d043daeb97a3d0856d177d5c90ba85acb3db087 \ From cd01b4b4bc4954dc72ca35c6a8c41010ed9a8638 Mon Sep 17 00:00:00 2001 From: Mehdi Samsami Date: Wed, 10 Jul 2024 14:48:00 +0330 Subject: [PATCH 3/3] add a new validator for sha384 hash (#387) --- CHANGES.md | 18 ++++++++++++++++++ SECURITY.md | 2 +- docs/api/hashes.md | 1 + docs/api/hashes.rst | 1 + src/validators/__init__.py | 5 +++-- src/validators/hashes.py | 24 ++++++++++++++++++++++++ tests/test_hashes.py | 34 ++++++++++++++++++++++++++++++++-- 7 files changed, 80 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3e069692..46517366 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,24 @@ Note to self: Breaking changes must increment either --> +## 0.32.0 (2024-07-10) + +_**Breaking**_ + +> No breaking changes were introduced in this version. + +_**Features**_ + +- feat: add validator for `sha384` hash by @msamsami in [#387](https://github.com/python-validators/validators/pull/387) + +_**Maintenance**_ + +- maint: bump version by @msamsami in [#387](https://github.com/python-validators/validators/pull/387) + +**Full Changelog**: [`0.31.0...0.32.0`](https://github.com/python-validators/validators/compare/0.31.0...0.32.0) + +--- + ## 0.31.0 (2024-07-08) _**Breaking**_ diff --git a/SECURITY.md b/SECURITY.md index dbf9c090..d828d524 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,7 +4,7 @@ | Version | Supported | | ---------- | ------------------ | -| `>=0.31.0` | :white_check_mark: | +| `>=0.32.0` | :white_check_mark: | ## Reporting a Vulnerability diff --git a/docs/api/hashes.md b/docs/api/hashes.md index 82b11bf0..8daeb033 100644 --- a/docs/api/hashes.md +++ b/docs/api/hashes.md @@ -4,4 +4,5 @@ ::: validators.hashes.sha1 ::: validators.hashes.sha224 ::: validators.hashes.sha256 +::: validators.hashes.sha384 ::: validators.hashes.sha512 diff --git a/docs/api/hashes.rst b/docs/api/hashes.rst index bc77b7b2..e8c15e5b 100644 --- a/docs/api/hashes.rst +++ b/docs/api/hashes.rst @@ -6,4 +6,5 @@ hashes .. autofunction:: sha1 .. autofunction:: sha224 .. autofunction:: sha256 +.. autofunction:: sha384 .. autofunction:: sha512 diff --git a/src/validators/__init__.py b/src/validators/__init__.py index cf11e3a7..3dfe1634 100644 --- a/src/validators/__init__.py +++ b/src/validators/__init__.py @@ -10,7 +10,7 @@ from .email import email from .encoding import base16, base32, base58, base64 from .finance import cusip, isin, sedol -from .hashes import md5, sha1, sha224, sha256, sha512 +from .hashes import md5, sha1, sha224, sha256, sha384, sha512 from .hostname import hostname from .i18n import ( es_cif, @@ -73,6 +73,7 @@ "sha1", "sha224", "sha256", + "sha384", "sha512", # ... "hostname", @@ -107,4 +108,4 @@ "validator", ) -__version__ = "0.31.0" +__version__ = "0.32.0" diff --git a/src/validators/hashes.py b/src/validators/hashes.py index 6004d30a..e544f7fe 100644 --- a/src/validators/hashes.py +++ b/src/validators/hashes.py @@ -94,6 +94,30 @@ def sha256(value: str, /): return re.match(r"^[0-9a-f]{64}$", value, re.IGNORECASE) if value else False +@validator +def sha384(value: str, /): + """Return whether or not given value is a valid SHA384 hash. + + Examples: + >>> sha384( + ... 'cb00753f45a35e8bb5a03d699ac65007272c32ab0eded163' + ... '1a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7' + ... ) + # Output: True + >>> sha384('900zz11') + # Output: ValidationError(func=sha384, args={'value': '900zz11'}) + + Args: + value: + SHA384 string to validate. + + Returns: + (Literal[True]): If `value` is a valid SHA384 hash. + (ValidationError): If `value` is an invalid SHA384 hash. + """ + return re.match(r"^[0-9a-f]{96}$", value, re.IGNORECASE) if value else False + + @validator def sha512(value: str, /): """Return whether or not given value is a valid SHA512 hash. diff --git a/tests/test_hashes.py b/tests/test_hashes.py index 39af2c4d..64f0affc 100644 --- a/tests/test_hashes.py +++ b/tests/test_hashes.py @@ -4,7 +4,7 @@ import pytest # local -from validators import ValidationError, base58, base64, md5, sha1, sha224, sha256, sha512 +from validators import ValidationError, base58, base64, md5, sha1, sha224, sha256, sha384, sha512 # ==> base58 <== # @@ -158,7 +158,37 @@ def test_returns_failed_validation_on_invalid_sha256(value: str): assert isinstance(sha256(value), ValidationError) -# ==> sha256 <== # +# ==> sha384 <== # + + +@pytest.mark.parametrize( + "value", + [ + "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", + "CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7", + "bfd76c0ebbd006fee583410547c1887b0292be76d582d96c242d2a792723e3fd6fd061f9d5cfd13b8f961358e6adba4a", + "F21EF1F8DBF806106813C8504AF864D8D9BFDFA8D67FA9B7DFF1C5B61C2584394A05897C4F157CEEE0E8FBC29205BB8B", + ], +) +def test_returns_true_on_valid_sha384(value: str): + """Test returns true on valid sha384.""" + assert sha384(value) + + +@pytest.mark.parametrize( + "value", + [ + "zb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", + "c753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", + "cb00aaaa753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", + ], +) +def test_returns_failed_validation_on_invalid_sha384(value: str): + """Test returns failed validation on invalid sha384.""" + assert isinstance(sha384(value), ValidationError) + + +# ==> sha512 <== # @pytest.mark.parametrize(