From f9be8ae4112e2cd66bd7700297ab876b4a13c18d Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Mon, 5 Dec 2022 11:52:31 +0100 Subject: [PATCH 1/2] Clippy fixes --- src/lib.rs | 78 ++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 42c5af4..9f6b8d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1009,14 +1009,13 @@ fn certify_key( cardkeys.push(pair); } if cardkeys.is_empty() { - return Err(JceError::new(format!( - "No key is available for certification in the public key." - ))); + return Err(JceError::new( + "No key is available for certification in the public key.".to_string(), + )); } // Now we know for sure that there is a key let key = cardkeys - .iter() - .next() + .first() .expect("We must have a certification key by now"); Some(key.clone()) @@ -1043,14 +1042,13 @@ fn certify_key( keys.push(key.into_keypair().unwrap()); } if keys.is_empty() { - return Err(JceError::new(format!( - "No key is available for certification." - ))); + return Err(JceError::new( + "No key is available for certification.".to_string(), + )); } // Now we know for sure that there is a key let key = keys - .iter() - .next() + .first() .expect("We must have a certification key by now"); Some(key.clone()) @@ -1071,11 +1069,11 @@ fn certify_key( let sig = match oncard { true => { let mut signer = card_signer.as_ref().unwrap().clone(); - u.certify(&mut signer, &othercert, stype.clone(), None, None)? + u.certify(&mut signer, &othercert, stype, None, None)? } false => { let mut signer = disk_signer.as_ref().unwrap().clone(); - u.certify(&mut signer, &othercert, stype.clone(), None, None)? + u.certify(&mut signer, &othercert, stype, None, None)? } }; new_certificates.push(sig); @@ -1575,7 +1573,7 @@ fn upload_primary_to_smartcard( let mut result = false; if (whichslot & 0x02) == 0x02 { - result = parse_and_move_a_key(cert.clone(), 2, pin.clone(), password.clone(), true)?; + result = parse_and_move_a_key(cert, 2, pin, password, true)?; } else if (whichslot & 0x04) == 0x04 { result = parse_and_move_a_key(cert, 3, pin, password, true)?; } @@ -1627,25 +1625,25 @@ fn get_signing_pubkey(py: Python, certdata: Vec) -> Result { let cert = openpgp::Cert::from_bytes(&certdata)?; let policy = P::new(); - let valid_ka = cert + let mut valid_ka = cert .keys() .with_policy(&policy, None) .alive() .revoked(false) .for_signing(); - for ka in valid_ka { + if let Some(ka) = valid_ka.next() { // First let us get the value of e from the public key let public = ka.parts_as_public(); match public.mpis().clone() { openpgp::crypto::mpi::PublicKey::RSA { ref e, ref n } => { let mut result_n = String::new(); let internal = n.value().to_vec(); - for v in internal.clone().iter() { + for v in internal.iter() { write!(&mut result_n, "{:02X}", v)?; } let mut result_e = String::new(); let internal = e.value().to_vec(); - for v in internal.clone().iter() { + for v in internal.iter() { write!(&mut result_e, "{:02X}", v)?; } pd.set_item("key_type", "RSA")?; @@ -1659,7 +1657,7 @@ fn get_signing_pubkey(py: Python, certdata: Vec) -> Result { }; } - return Err(JceError::new("Could not find signing key.".to_string())); + Err(JceError::new("Could not find signing key.".to_string())) } #[pyfunction] @@ -1668,14 +1666,14 @@ fn get_ssh_pubkey(_py: Python, certdata: Vec, comment: Option) -> Re let cert = openpgp::Cert::from_bytes(&certdata)?; let policy = P::new(); - let valid_ka = cert + let mut valid_ka = cert .keys() .subkeys() .with_policy(&policy, None) .alive() .revoked(false) .for_authentication(); - for ka in valid_ka { + if let Some(ka) = valid_ka.next() { // First let us get the value of e from the public key let public = ka.parts_as_public(); let (key_type, kind) = match public.mpis().clone() { @@ -1729,7 +1727,7 @@ fn get_ssh_pubkey(_py: Python, certdata: Vec, comment: Option) -> Re let public_key = sshkeys::PublicKey { key_type, kind, - comment: comment, + comment, }; let mut keydata = vec![]; public_key.write(&mut keydata)?; @@ -1738,9 +1736,9 @@ fn get_ssh_pubkey(_py: Python, certdata: Vec, comment: Option) -> Re return Ok(s); } - return Err(JceError::new( + Err(JceError::new( "Could not find authentication subkey for ssh.".to_string(), - )); + )) } #[allow(unused)] @@ -1861,19 +1859,19 @@ fn parse_and_move_a_key( main_n = Some(n.clone()); } openpgp::crypto::mpi::PublicKey::ECDH { curve, q, .. } => { - main_curve = Some(curve.clone()); - main_eq = Some(q.clone()); + main_curve = Some(curve); + main_eq = Some(q); } openpgp::crypto::mpi::PublicKey::EdDSA { curve, q } => { - main_curve = Some(curve.clone()); - main_eq = Some(q.clone()); + main_curve = Some(curve); + main_eq = Some(q); } _ => (), } let key = ka .key() .clone() - .decrypt_secret(&openpgp::crypto::Password::from(password.clone()))?; + .decrypt_secret(&openpgp::crypto::Password::from(password))?; let ctime = key.creation_time(); let dt: DateTime = DateTime::from(ctime); ts = dt.timestamp() as u64; @@ -3068,24 +3066,12 @@ pub fn get_keyslot_touch_policy(py: Python, slot: Py) -> Result return Err(JceError::new(e.to_string())), }; match data[0] { - 0 => { - return Ok(Py::new(py, TouchMode::Off)?); - } - 1 => { - return Ok(Py::new(py, TouchMode::On)?); - } - 2 => { - return Ok(Py::new(py, TouchMode::Fixed)?); - } - 3 => { - return Ok(Py::new(py, TouchMode::Cached)?); - } - 4 => { - return Ok(Py::new(py, TouchMode::CachedFixed)?); - } - _ => { - return Err(JceError::new("Can not parse touch policy.".to_string())); - } + 0 => Ok(Py::new(py, TouchMode::Off)?), + 1 => Ok(Py::new(py, TouchMode::On)?), + 2 => Ok(Py::new(py, TouchMode::Fixed)?), + 3 => Ok(Py::new(py, TouchMode::Cached)?), + 4 => Ok(Py::new(py, TouchMode::CachedFixed)?), + _ => Err(JceError::new("Can not parse touch policy.".to_string())), } } From 2b2ee048f161eb1dd2be9a5bdafaef87108b797b Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Mon, 5 Dec 2022 12:07:49 +0100 Subject: [PATCH 2/2] Updates to 0.11.1 --- .gitignore | 1 - Cargo.toml | 2 +- MANIFEST.in | 3 ++- changelog.md | 8 +++++++- docs/conf.py | 4 ++-- pyproject.toml | 2 +- setup.py | 2 +- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index f3dbff0..c2d5013 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ .venv /target smartcardtests/jce.db -Cargo.lock src/.lib.rs.rustfmt __pycache__ /johnnycanencrypt/johnnycanencrypt*.so diff --git a/Cargo.toml b/Cargo.toml index 22ad1de..eb31cc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "johnnycanencrypt" -version = "0.11.0" +version = "0.11.1" authors = ["Kushal Das "] edition = "2018" description = "Python module for OpenPGP." diff --git a/MANIFEST.in b/MANIFEST.in index 77d54a5..05d3b05 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ include Cargo.toml +include Cargo.lock recursive-include src * recursive-include tests * recursive-include docs * @@ -7,4 +8,4 @@ include changelog.md include README.md include requirements-dev.txt global-exclude *.py[cod] -prune docs/_build/* \ No newline at end of file +prune docs/_build/* diff --git a/changelog.md b/changelog.md index defe4ed..851ea0f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,13 @@ -# Changlelog +# Changelog ## [unreleased] +## [0.11.1] - 2022-12-05 + +### Added + +- Trying to fix the wheels for Mac. + ## [0.11.0] - 2022-11-09 ### Added diff --git a/docs/conf.py b/docs/conf.py index 3a3511a..46ed0c5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,9 +24,9 @@ author = 'Kushal Das' # The short X.Y version -version = '0.11.0' +version = '0.11.1' # The full version, including alpha/beta/rc tags -release = '0.11.0' +release = '0.11.1' # -- General configuration --------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 9d8687c..64fddba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel", "setuptools-rust"] [project] name = "johnnycanencrypt" -version = "0.11.0" +version = "0.11.1" classifiers = [ "Development Status :: 4 - Beta", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", diff --git a/setup.py b/setup.py index 3805bf7..659adbb 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="johnnycanencrypt", - version="0.11.0", + version="0.11.1", rust_extensions=[ RustExtension("johnnycanencrypt.johnnycanencrypt", binding=Binding.PyO3) ],