diff --git a/MANIFEST.in b/MANIFEST.in index b9486402..bf27c068 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,13 +5,12 @@ include pyproject.toml include tox.ini .coveragerc recursive-include src py.typed *.pyi -recursive-include src/_bcrypt Cargo.toml Cargo.lock *.rs +recursive-include src/bcrypt Cargo.toml Cargo.lock *.rs recursive-include tests *.py exclude requirements.txt release.py mypy.ini recursive-exclude .github * -recursive-exclude .circleci * -exclude src/_bcrypt/target -recursive-exclude src/_bcrypt/target * +exclude src/bcrypt/target +recursive-exclude src/bcrypt/target * diff --git a/setup.cfg b/setup.cfg index a706302f..68238b6d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,7 @@ [metadata] name = bcrypt -version = attr: bcrypt.__about__.__version__ +# When updating this, also update lib.rs +version = 4.0.1 description = Modern password hashing for your software and your servers long_description = file: README.rst long_description_content_type = text/x-rst @@ -24,14 +25,9 @@ classifiers = Programming Language :: Python :: 3.12 [options] -python_requires = >=3.6 +python_requires = >=3.7 include_package_data = True zip_safe = False -package_dir = - =src -packages = - bcrypt -ext_package = bcrypt [options.extras_require] tests = diff --git a/setup.py b/setup.py index c5f5c452..624cee8b 100644 --- a/setup.py +++ b/setup.py @@ -35,8 +35,8 @@ setup( rust_extensions=[ RustExtension( - "_bcrypt", - "src/_bcrypt/Cargo.toml", + "bcrypt", + "src/bcrypt/Cargo.toml", py_limited_api=True, # Enable abi3 mode if we're not using PyPy. features=( diff --git a/src/bcrypt/_bcrypt.pyi b/src/bcrypt.pyi similarity index 100% rename from src/bcrypt/_bcrypt.pyi rename to src/bcrypt.pyi diff --git a/src/_bcrypt/Cargo.lock b/src/bcrypt/Cargo.lock similarity index 100% rename from src/_bcrypt/Cargo.lock rename to src/bcrypt/Cargo.lock diff --git a/src/_bcrypt/Cargo.toml b/src/bcrypt/Cargo.toml similarity index 89% rename from src/_bcrypt/Cargo.toml rename to src/bcrypt/Cargo.toml index 05cca00f..73c5e803 100644 --- a/src/_bcrypt/Cargo.toml +++ b/src/bcrypt/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] pyo3 = { version = "0.20.0" } -bcrypt = "0.15" +bcrypt-rs = { package = "bcrypt", version = "0.15" } bcrypt-pbkdf = "0.10.0" base64 = "0.21.5" subtle = "2.5" diff --git a/src/bcrypt/__about__.py b/src/bcrypt/__about__.py deleted file mode 100644 index 020b748e..00000000 --- a/src/bcrypt/__about__.py +++ /dev/null @@ -1,41 +0,0 @@ -# Author:: Donald Stufft () -# Copyright:: Copyright (c) 2013 Donald Stufft -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import absolute_import -from __future__ import division -from __future__ import unicode_literals - -__all__ = [ - "__title__", - "__summary__", - "__uri__", - "__version__", - "__author__", - "__email__", - "__license__", - "__copyright__", -] - -__title__ = "bcrypt" -__summary__ = "Modern password hashing for your software and your servers" -__uri__ = "https://github.com/pyca/bcrypt/" - -__version__ = "4.0.1" - -__author__ = "The Python Cryptographic Authority developers" -__email__ = "cryptography-dev@python.org" - -__license__ = "Apache License, Version 2.0" -__copyright__ = "Copyright 2013-2022 {0}".format(__author__) diff --git a/src/bcrypt/__init__.py b/src/bcrypt/__init__.py deleted file mode 100644 index 6663d7c3..00000000 --- a/src/bcrypt/__init__.py +++ /dev/null @@ -1,51 +0,0 @@ -# Author:: Donald Stufft () -# Copyright:: Copyright (c) 2013 Donald Stufft -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import absolute_import -from __future__ import division - -from .__about__ import ( - __author__, - __copyright__, - __email__, - __license__, - __summary__, - __title__, - __uri__, - __version__, -) -from . import _bcrypt # noqa: I100 - - -__all__ = [ - "__title__", - "__summary__", - "__uri__", - "__version__", - "__author__", - "__email__", - "__license__", - "__copyright__", - "gensalt", - "hashpw", - "kdf", - "checkpw", -] - - -gensalt = _bcrypt.gensalt -hashpw = _bcrypt.hashpass -checkpw = _bcrypt.checkpass -kdf = _bcrypt.pbkdf diff --git a/src/_bcrypt/src/lib.rs b/src/bcrypt/src/lib.rs similarity index 86% rename from src/_bcrypt/src/lib.rs rename to src/bcrypt/src/lib.rs index ceeba08e..40559540 100644 --- a/src/_bcrypt/src/lib.rs +++ b/src/bcrypt/src/lib.rs @@ -80,10 +80,10 @@ fn hashpass<'p>( return Err(pyo3::exceptions::PyValueError::new_err("Invalid salt")); } let version = match raw_parts[0] { - b"2y" => bcrypt::Version::TwoY, - b"2b" => bcrypt::Version::TwoB, - b"2a" => bcrypt::Version::TwoA, - b"2x" => bcrypt::Version::TwoX, + b"2y" => bcrypt_rs::Version::TwoY, + b"2b" => bcrypt_rs::Version::TwoB, + b"2a" => bcrypt_rs::Version::TwoA, + b"2x" => bcrypt_rs::Version::TwoX, _ => { return Err(pyo3::exceptions::PyValueError::new_err("Invalid salt")); } @@ -102,7 +102,7 @@ fn hashpass<'p>( .map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?; let hashed = py - .allow_threads(|| bcrypt::hash_with_salt(password, cost, raw_salt)) + .allow_threads(|| bcrypt_rs::hash_with_salt(password, cost, raw_salt)) .map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?; Ok(pyo3::types::PyBytes::new( py, @@ -172,11 +172,25 @@ fn pbkdf<'p>( } #[pyo3::prelude::pymodule] -fn _bcrypt(_py: pyo3::Python<'_>, m: &pyo3::types::PyModule) -> pyo3::PyResult<()> { +fn bcrypt(_py: pyo3::Python<'_>, m: &pyo3::types::PyModule) -> pyo3::PyResult<()> { m.add_function(pyo3::wrap_pyfunction!(gensalt, m)?)?; m.add_function(pyo3::wrap_pyfunction!(hashpass, m)?)?; m.add_function(pyo3::wrap_pyfunction!(checkpass, m)?)?; m.add_function(pyo3::wrap_pyfunction!(pbkdf, m)?)?; + m.add("__title__", "bcrypt")?; + m.add("__summary__", "Modern(-ish) password hashing for your software and your servers")?; + m.add("__uri__", "https://github.com/pyca/bcrypt/")?; + + // When updating this, also update setup.cfg + m.add("__version__", "4.0.1")?; + + let author = "The Python Cryptographic Authority developers"; + m.add("__author__", author)?; + m.add("__email__", "cryptography-dev@python.org")?; + + m.add("__license__", "Apache License, Version 2.0")?; + m.add("__copyright__", format!("Copyright 2013-2022 {author}"))?; + Ok(()) }