Skip to content

Commit c4a3b44

Browse files
committed
cleanup
1 parent 4acfbe1 commit c4a3b44

File tree

2 files changed

+1
-50
lines changed

2 files changed

+1
-50
lines changed

src/rust/src/backend/keys.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use pyo3::IntoPyObject;
66

7-
use crate::backend::utils;
87
use crate::buf::CffiBuf;
98
use crate::error::{CryptographyError, CryptographyResult};
109
use crate::exceptions;
@@ -117,7 +116,7 @@ fn load_pem_private_key<'p>(
117116
))
118117
}
119118
};
120-
let iv = utils::hex_decode(iv).ok_or_else(|| {
119+
let iv = cryptography_crypto::encoding::hex_decode(iv).ok_or_else(|| {
121120
pyo3::exceptions::PyValueError::new_err("DEK-Info IV is not valid hex")
122121
})?;
123122
let key = cryptography_crypto::pbkdf1::openssl_kdf(

src/rust/src/backend/utils.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -402,51 +402,3 @@ pub(crate) fn calculate_digest_and_algorithm<'p>(
402402

403403
Ok((data, algorithm))
404404
}
405-
406-
pub(crate) fn hex_decode(v: &str) -> Option<Vec<u8>> {
407-
if v.len() % 2 != 0 {
408-
return None;
409-
}
410-
411-
let mut b = Vec::with_capacity(v.len() / 2);
412-
let v = v.as_bytes();
413-
for i in (0..v.len()).step_by(2) {
414-
let high = match v[i] {
415-
b @ b'0'..=b'9' => b - b'0',
416-
b @ b'a'..=b'f' => b - b'a' + 10,
417-
b @ b'A'..=b'F' => b - b'A' + 10,
418-
_ => return None,
419-
};
420-
421-
let low = match v[i + 1] {
422-
b @ b'0'..=b'9' => b - b'0',
423-
b @ b'a'..=b'f' => b - b'a' + 10,
424-
b @ b'A'..=b'F' => b - b'A' + 10,
425-
_ => return None,
426-
};
427-
428-
b.push((high << 4) | low);
429-
}
430-
431-
Some(b)
432-
}
433-
434-
#[cfg(test)]
435-
mod tests {
436-
use super::hex_decode;
437-
438-
#[test]
439-
fn test_hex_decode() {
440-
for (text, expected) in [
441-
("", Some(vec![])),
442-
("00", Some(vec![0])),
443-
("0", None),
444-
("12-0", None),
445-
("120-", None),
446-
("ab", Some(vec![0xAB])),
447-
("AB", Some(vec![0xAB])),
448-
] {
449-
assert_eq!(hex_decode(text), expected);
450-
}
451-
}
452-
}

0 commit comments

Comments
 (0)