From a6690b0057b63482d02d061e7bfa68bb0364f7e9 Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Wed, 8 Nov 2023 09:24:30 +0100 Subject: [PATCH 1/4] Fixes #144 runs tests on windows --- .github/workflows/windows_ci.yml | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/windows_ci.yml diff --git a/.github/workflows/windows_ci.yml b/.github/workflows/windows_ci.yml new file mode 100644 index 0000000..a3b8b58 --- /dev/null +++ b/.github/workflows/windows_ci.yml @@ -0,0 +1,46 @@ +name: Tests on Windows +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + name: Build and run tests on Windows + runs-on: windows-latest + strategy: + matrix: + python-version: ["3.10","3.11","3.12"] + platform: [{ os: "windows-latest", python-architecture: "x64", rust-target: "x86_64-pc-windows-msvc" }] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + architecture: ${{ matrix.platform.python-architecture }} + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.platform.rust-target }} + + - name: Install build dependencies + shell: bash + env: + PYTHON: ${{ matrix.python-version }} + run: | + python -m pip install -U pip setuptools + python -m pip install -r requirements-dev.txt + + - name: Build wheel + shell: bash + env: + PYTHON: ${{ matrix.python-version }} + run: python setup.py develop + + - name: Run tests + env: + PYTHON: ${{ matrix.python-version }} + run: python -m pytest -vvv + + + From 678f1a032946b9ba2fff8388567cf537b832faa7 Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Tue, 14 Nov 2023 20:41:40 +0100 Subject: [PATCH 2/4] Updates tests and upgrade_if_required for windows We have an internal function to close of all the connections to the sqlite3 database. --- johnnycanencrypt/__init__.py | 26 ++++++++++++++++++++------ tests/test_sign_verify_bytes.py | 8 ++++---- tests/utils.py | 4 ++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/johnnycanencrypt/__init__.py b/johnnycanencrypt/__init__.py index 5a26f95..43d596f 100644 --- a/johnnycanencrypt/__init__.py +++ b/johnnycanencrypt/__init__.py @@ -4,6 +4,7 @@ import os import sqlite3 import urllib.parse +import shutil from datetime import datetime from enum import Enum from typing import Dict, List, Optional, Union, Tuple, Any @@ -183,6 +184,17 @@ def __str__(self) -> str: def upgrade_if_required(self): "Upgrades the database schema if required" + oldpath = self._upgrade_if_required() + if oldpath is None: + return + os.unlink(oldpath) + # Now let us rename the file + shutil.copy(self.dbpath, oldpath) + os.unlink(self.dbpath) + self.dbpath = oldpath + + def _upgrade_if_required(self): + "Internal: Upgrades the database schema if required" SHOULD_WE = False existing_records = [] con = sqlite3.connect(self.dbpath) @@ -205,6 +217,7 @@ def upgrade_if_required(self): existing_records = cursor.fetchall() else: return + con.close() # Temporay db setup oldpath = self.dbpath self.dbpath = self.path / "jce_upgrade.db" @@ -222,6 +235,7 @@ def upgrade_if_required(self): cursor.execute( "INSERT INTO dbupgrade (upgradedate) values (?)", (DB_UPGRADE_DATE,) ) + con.close() # now let us insert our existing data for row in existing_records: ( @@ -255,9 +269,8 @@ def upgrade_if_required(self): fingerprint = row["fingerprint"] sql = "UPDATE keys set oncard=?, primary_on_card=? where fingerprint=?" cursor.execute(sql, (oncard, primary_on_card, fingerprint)) - # Now let us rename the file - os.rename(self.dbpath, oldpath) - self.dbpath = oldpath + con.close() + return oldpath def update_password(self, key: Key, password: str, newpassword: str) -> Key: """Updates the password of the given key and saves to the database""" @@ -464,6 +477,7 @@ def _save_key_info_to_db( value = uid[uid_keyname] sql = f"INSERT INTO {tablename} (value, key_id, value_id) values (?, ?, ?)" cursor.execute(sql, (value, key_id, value_id)) + con.close() def __contains__(self, other: Union[str, Key]) -> bool: """Checks if a Key object of fingerprint str exists in the keystore or not. @@ -536,7 +550,7 @@ def update_expiry_in_subkeys( sql, (etime_str, subkey[1]), ) - + con.close() # Regnerate the key object and return it return self.get_key(fingerprint) @@ -605,7 +619,7 @@ def add_userid(self, key: Key, userid: str, password: str) -> Key: value = uid[uid_keyname] sql = f"INSERT INTO {tablename} (value, key_id, value_id) values (?, ?, ?)" cursor.execute(sql, (value, key_id, value_id)) - + con.close() # Regnerate the key object and return it return self.get_key(fingerprint) @@ -658,7 +672,7 @@ def revoke_userid(self, key: Key, userid: str, password: str) -> Key: revoked = 1 sql = "UPDATE uidvalues set revoked=? where id=?" cursor.execute(sql, (revoked, value_id)) - + con.close() # Regnerate the key object and return it return self.get_key(fingerprint) diff --git a/tests/test_sign_verify_bytes.py b/tests/test_sign_verify_bytes.py index bf20a83..f098afe 100644 --- a/tests/test_sign_verify_bytes.py +++ b/tests/test_sign_verify_bytes.py @@ -51,11 +51,11 @@ def test_sign_verify_file_cleartext(tmp_path): True, ) assert os.path.exists(output) - with open(output) as fobj: + with open(output, "rb") as fobj: data = fobj.read() - assert data.startswith("-----BEGIN PGP SIGNED MESSAGE-----") - assert "🦄🦄🦄" in data - assert data.endswith("-----END PGP SIGNATURE-----\n") + assert data.startswith(b"-----BEGIN PGP SIGNED MESSAGE-----") + assert "🦄🦄🦄".encode("utf-8") in data + assert data.endswith(b"-----END PGP SIGNATURE-----\n") jp = jce.Johnny(_get_cert_data(PUBLIC_PATH)) assert jp.verify_file(output.encode("utf-8")) diff --git a/tests/utils.py b/tests/utils.py index 331a7c9..6e4b8fb 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -6,9 +6,9 @@ def _get_cert_data(filepath): def verify_files(inputfile, decrypted_output): # read both the files - with open(inputfile) as f: + with open(inputfile, "rb") as f: original_text = f.read() - with open(decrypted_output) as f: + with open(decrypted_output, "rb") as f: decrypted_text = f.read() assert original_text == decrypted_text From 53c79ae8b4868c8be680b406e20204421ef63b46 Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Tue, 14 Nov 2023 20:55:56 +0100 Subject: [PATCH 3/4] Updates changelog --- changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/changelog.md b/changelog.md index b3cbcb7..15b1f0a 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,14 @@ ### Fixed - Fixes #140, updates dependencies. +- Fixes #146 ks.get_key(None) raises correct error. + +### Added + +- Adds `pathlib.Path` support to `KeyStore` #148. +- Adds Windows CI support #144. +- Updates pyo3 to `0.20.0` + ## [0.14.1] - 2023-05-21 From 587eb73698c4bc8c6827858b716040155618a7c7 Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Tue, 14 Nov 2023 21:01:08 +0100 Subject: [PATCH 4/4] Updates time to 0.3.30 --- Cargo.lock | 216 +++++++-------------------------------------------- Cargo.toml | 2 +- changelog.md | 1 + 3 files changed, 30 insertions(+), 189 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8eacb3..950820d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,12 +82,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - [[package]] name = "base64" version = "0.12.3" @@ -322,12 +316,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -390,7 +378,7 @@ dependencies = [ "digest 0.10.7", "fiat-crypto", "platforms", - "rustc_version 0.4.0", + "rustc_version", "subtle", "zeroize", ] @@ -469,6 +457,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", +] + [[package]] name = "diff" version = "0.1.13" @@ -516,12 +513,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "doc-comment" version = "0.3.3" @@ -811,12 +802,6 @@ dependencies = [ "either", ] -[[package]] -name = "itoa" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" - [[package]] name = "johnnycanencrypt" version = "0.14.1" @@ -829,7 +814,7 @@ dependencies = [ "sshkeys", "talktosc", "tempfile", - "time 0.2.27", + "time 0.3.30", ] [[package]] @@ -1183,6 +1168,12 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1195,12 +1186,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.56" @@ -1374,22 +1359,13 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.20", + "semver", ] [[package]] @@ -1412,12 +1388,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" -[[package]] -name = "ryu" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" - [[package]] name = "scopeguard" version = "1.1.0" @@ -1430,27 +1400,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - [[package]] name = "semver" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "sequoia-openpgp" version = "1.17.0" @@ -1492,46 +1447,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.163" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" - -[[package]] -name = "serde_derive" -version = "1.0.163" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.15", -] - -[[package]] -name = "serde_json" -version = "1.0.96" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha1" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" -dependencies = [ - "sha1_smol", -] - -[[package]] -name = "sha1_smol" -version = "1.0.0" +version = "1.0.185" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" [[package]] name = "sha1collisiondetection" @@ -1617,64 +1535,6 @@ dependencies = [ "sha2 0.8.2", ] -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] - -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version 0.2.3", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn 1.0.109", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1", - "syn 1.0.109", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "string_cache" version = "0.8.7" @@ -1798,41 +1658,21 @@ dependencies = [ [[package]] name = "time" -version = "0.2.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros", - "version_check", - "winapi", -] - -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", + "deranged", + "powerfmt", + "serde", + "time-core", ] [[package]] -name = "time-macros-impl" +name = "time-core" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn 1.0.109", -] +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "tiny-keccak" diff --git a/Cargo.toml b/Cargo.toml index f7d2124..c889364 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ tempfile = "3.0.0" talktosc = "0.2" sshkeys = "0.3.2" regex = "1" -time = "0.2" +time = "0.3" [target.'cfg(not(target_os = "windows"))'.dependencies] sequoia-openpgp = { default-features = false, features = ["crypto-nettle", "compression"] } diff --git a/changelog.md b/changelog.md index 15b1f0a..9a6729d 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ - Adds `pathlib.Path` support to `KeyStore` #148. - Adds Windows CI support #144. - Updates pyo3 to `0.20.0` +- Updates time to `0.3.30` ## [0.14.1] - 2023-05-21