Skip to content

Commit

Permalink
Upgrade base64 crate (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Jul 6, 2023
1 parent 16dfdc3 commit 905fdcd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
10 changes: 2 additions & 8 deletions src/_bcrypt/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/_bcrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
pyo3 = { version = "0.19.1" }
bcrypt = "0.15"
bcrypt-pbkdf = "0.10.0"
base64 = "0.13.1"
base64 = "0.21.1"

[features]
extension-module = ["pyo3/extension-module"]
Expand Down
11 changes: 9 additions & 2 deletions src/_bcrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

#![deny(rust_2018_idioms)]

use base64::Engine;
use std::convert::TryInto;

pub const BASE64_ENGINE: base64::engine::GeneralPurpose = base64::engine::GeneralPurpose::new(
&base64::alphabet::BCRYPT,
base64::engine::general_purpose::NO_PAD,
);

#[pyo3::prelude::pyfunction]
fn encode_base64<'p>(py: pyo3::Python<'p>, data: &[u8]) -> &'p pyo3::types::PyBytes {
let output = base64::encode_config(data, base64::BCRYPT);
let output = BASE64_ENGINE.encode(data);
pyo3::types::PyBytes::new(py, output.as_bytes())
}

Expand Down Expand Up @@ -44,7 +50,8 @@ fn hashpass<'p>(
// The last component can contain either just the salt, or the salt and
// the result hash, depending on if the `salt` value come from `hashpw` or
// `gensalt`.
let raw_salt = base64::decode_config(&raw_parts[2][..22], base64::BCRYPT)
let raw_salt = BASE64_ENGINE
.decode(&raw_parts[2][..22])
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?
.try_into()
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?;
Expand Down

0 comments on commit 905fdcd

Please sign in to comment.