Repository: naufraghi/tinyaes-py (language: python)

Issue:
Release wheels for Python 3.12
It's possible to test the prr-releases on windows too, using this guide:

- https://cibuildwheel.readthedocs.io/en/latest/options/#prerelease-pythons


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml
index c3f7c7c..63ec242 100644
--- a/.github/workflows/build_and_upload.yml
+++ b/.github/workflows/build_and_upload.yml
@@ -22,7 +22,7 @@ jobs:
         env:
           CIBW_BUILD_VERBOSITY: 1
           CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
-          CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-*"
+          CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* cp312-*"
           CIBW_SKIP: "pp* *-musllinux* *_aarch64 *_ppc64le *_s390x *_i686"
 
       - uses: actions/upload-artifact@v3
diff --git a/README.md b/README.md
index 8536290..adea22b 100644
--- a/README.md
+++ b/README.md
@@ -12,12 +12,13 @@ Given the C API works modifying a buffer in-place, the wrapper offers:
   encrypting a copy of the buffer,
 - `CTR_xcrypt_buffer_inplace(..)` that works on `bytearray`s only, modifying
   the buffer in-place.
-- `CBC_encrypt_buffer_inplace(..)` that works on `bytearray`s only, modifying
-  the buffer in-place.
-- `CBC_decrypt_buffer_inplace(..)` that works on `bytearray`s only, modifying
-  the buffer in-place.
+- `CBC_encrypt_buffer_inplace_raw(..)` that works on `bytearray`s only, modifying
+  the buffer in-place (manual padding).
+- `CBC_decrypt_buffer_inplace_raw(..)` that works on `bytearray`s only, modifying
+  the buffer in-place (manual unpadding).
+
+<details><summary>CBC usage Example:</summary>
 
-CBC usage Example:
 ```
 import tinyaes
 import binascii
@@ -42,14 +43,19 @@ print(text)  # b'hello'
 # padding plaintext to a multiple of block size
 text = pad(text)
 print(binascii.hexlify(bytearray(text)))  # b'68656c6c6f0b0b0b0b0b0b0b0b0b0b0b' hex representation of added text
-aes_enc.CBC_encrypt_buffer_inplace(text)  # b'5adc04828f9421c34210b05fe5c92bfd' hex representation of encrypted text
+aes_enc.CBC_encrypt_buffer_inplace_raw(text)  # b'5adc04828f9421c34210b05fe5c92bfd' hex representation of encrypted text
 print(binascii.hexlify(bytearray(text)))
-aes_dec.CBC_decrypt_buffer_inplace(text)
+aes_dec.CBC_decrypt_buffer_inplace_raw(text)
 print(unpad(text)) # b'hello' decrypted, original text
 ```
 
+</details>
+
 ## Release notes
 
+- 1.1.0rc1 (Oct 2, 2023)
+  - Add Python 3.12 final to the matrix
+  - Expose _raw_ functions for CBC mode, with manual padding and unpadding
 - 1.1.0rc0 (13 Feb 2023)
   - Drop support for Python 2.7 (CI tests and builds are disabled, code may still work)
   - Add support for CBC mode (unstable API, inplace only, manual padding)
diff --git a/setup.py b/setup.py
index e15aede..c6070e6 100644
--- a/setup.py
+++ b/setup.py
@@ -30,7 +30,7 @@
     description="tiny-AES-c wrapper in Cython",
     long_description=long_description,
     long_description_content_type="text/markdown",
-    version="1.1.0rc0",
+    version="1.1.0rc1",
     author="Matteo Bertini",
     author_email="naufraghi@develer.com",
     url="https://github.com/naufraghi/tinyaes-py",
diff --git a/tinyaes.pyx b/tinyaes.pyx
index e589572..1e20330 100644
--- a/tinyaes.pyx
+++ b/tinyaes.pyx
@@ -31,11 +31,11 @@ cdef class AES:
     def CTR_xcrypt_buffer_inplace(self, bytearray data):
         tinyaes.AES_CTR_xcrypt_buffer(&self._ctx, data, len(data))
 
-    def CBC_encrypt_buffer_inplace(self, data):
+    def CBC_encrypt_buffer_inplace_raw(self, data):
         if len(data) % AES_KEYLEN:
             raise ValueError(f"Length of plaintext must be multiple of {AES_KEYLEN} bytes")
         tinyaes.AES_CBC_encrypt_buffer(&self._ctx, data, len(data))
-    def CBC_decrypt_buffer_inplace(self, data):
+    def CBC_decrypt_buffer_inplace_raw(self, data):
         if len(data) % AES_KEYLEN:
             raise ValueError(f"Length of plaintext must be multiple of {AES_KEYLEN} bytes")
         tinyaes.AES_CBC_decrypt_buffer(&self._ctx, data, len(data))


Test patch:
diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml
index be405e3..b4e7910 100644
--- a/.github/workflows/build_and_test.yml
+++ b/.github/workflows/build_and_test.yml
@@ -8,7 +8,7 @@ jobs:
     continue-on-error: ${{ endsWith(matrix.python-version, 'dev') }}
     strategy:
       matrix:
-        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
+        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
     steps:
     - uses: actions/checkout@v3
     - name: Set up Python ${{ matrix.python-version }}
@@ -29,7 +29,7 @@ jobs:
     continue-on-error: ${{ endsWith(matrix.python-version, 'dev') }}
     strategy:
       matrix:
-        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
+        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
     steps:
     - uses: actions/checkout@v3
     - name: Set up Python ${{ matrix.python-version }}
@@ -50,7 +50,7 @@ jobs:
     continue-on-error: ${{ endsWith(matrix.python-version, 'dev') }}
     strategy:
       matrix:
-        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
+        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
     steps:
     - uses: actions/checkout@v3
     - name: Set up Python ${{ matrix.python-version }}
diff --git a/tests/test_tinyaes.py b/tests/test_tinyaes.py
index cb01e15..79ade68 100644
--- a/tests/test_tinyaes.py
+++ b/tests/test_tinyaes.py
@@ -116,8 +116,8 @@ def test_different_keys_do_not_decode(data, aes_enc, aes_dec2, aes_dec3):
 def test_different_keys_do_not_decode_cbc(data, aes_enc_cbc, aes_dec2_cbc):
     data = pad(data)
     original_data = data[:len(data) // 2] + data[len(data) // 2:]  # Force a copy not allowing any sharing
-    aes_enc_cbc.CBC_encrypt_buffer_inplace(data)
-    aes_dec2_cbc.CBC_decrypt_buffer_inplace(data)
+    aes_enc_cbc.CBC_encrypt_buffer_inplace_raw(data)
+    aes_dec2_cbc.CBC_decrypt_buffer_inplace_raw(data)
     assert data != original_data
 
 
@@ -125,12 +125,12 @@ def test_different_keys_do_not_decode_cbc(data, aes_enc_cbc, aes_dec2_cbc):
 def test_cbc_decode(data, aes_enc2_cbc, aes_dec_cbc):
     data = pad(data)
     original_data = data[:len(data) // 2] + data[len(data) // 2:]  # Force a copy not allowing any sharing
-    aes_enc2_cbc.CBC_encrypt_buffer_inplace(data)
-    aes_dec_cbc.CBC_decrypt_buffer_inplace(data)
+    aes_enc2_cbc.CBC_encrypt_buffer_inplace_raw(data)
+    aes_dec_cbc.CBC_decrypt_buffer_inplace_raw(data)
     assert data == original_data
 
 
 def test_bad_block_size_cbc(aes_enc_cbc, aes_dec2_cbc):
     data = bytes.fromhex('00112233445566778899AA')
     with pytest.raises(ValueError, match=r"Length of plaintext must be multiple of.*"):
-        aes_enc_cbc.CBC_encrypt_buffer_inplace(data)
+        aes_enc_cbc.CBC_encrypt_buffer_inplace_raw(data)