Skip to content

Commit

Permalink
Everything is Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Nov 23, 2023
1 parent fb89f7c commit f28a515
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 112 deletions.
7 changes: 3 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
10 changes: 3 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/_bcrypt/Cargo.toml → src/bcrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
41 changes: 0 additions & 41 deletions src/bcrypt/__about__.py

This file was deleted.

51 changes: 0 additions & 51 deletions src/bcrypt/__init__.py

This file was deleted.

26 changes: 20 additions & 6 deletions src/_bcrypt/src/lib.rs → src/bcrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand All @@ -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,
Expand Down Expand Up @@ -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(())
}

0 comments on commit f28a515

Please sign in to comment.