8000 Write the repeated parts of crypto.rs once and split its long functions by dominion525 · Pull Request #130 · dominion525/jetdb · GitHub
[go: up one dir, main page]

Skip to content

Write the repeated parts of crypto.rs once and split its long functions - #130

Merged
dominion525 merged 2 commits into
mainfrom
refactor/crypto
Oct 25, 2026
Merged

dominion525 merged 2 commits into
mainfrom
refactor/crypto

Conversation

@dominion525
Copy link
Copy Markdown
Owner

Summary

  • Ten functions of crypto.rs were above the complexity thresholds of scripts/quality-check.sh (CC ≥ 10, cognitive ≥ 10 or SLOC ≥ 50), and none of the file is now.
  • The first commit adds tests of paths no test took: Standard AES with the AES flag, the key size of each AES algId when keySize is 0, and the messages of the errors for an unknown algId or version, a short EncryptionInfo and one without the CryptoAPI flag. They pass before and after the second commit.
  • The second commit writes the repeated parts once: AES-CBC and AES-ECB decryption, which four functions each did with the same match on the key length, the reading of the EncryptionHeader, and the AES key size when keySize is 0. The version check of the EncryptionInfo and the reading of Agile XML are split into functions. The kinds and messages of the errors are unchanged.
  • Functions above the thresholds: 117 → 107. Tests: 1104 → 1108. Line coverage of crypto.rs: 87.01% → 95.44%.
Function Before (CC / Cog / SLOC) After, the largest function
parse_cryptoapi_info 25 / 26 / 84 8 / 2 / 24
parse_encrypted_key 17 / 0 / 27 9 / 0 / 25
parse_encryption_info 15 / 12 / 81 8 / 2 / 31
parse_agile_encryption_info 15 / 3 / 55 7 / 1 / 27
parse_standard_aes_info 14 / 12 / 57 4 / 0 / 9
decrypt_page_agile 13 / 3 / 70 3 / 2 / 37
decrypt_page_standard_aes 13 / 3 / 53 3 / 2 / 29
aes_cbc_decrypt 12 / 3 / 54 6 / 3 / 19
aes_ecb_decrypt 12 / 3 / 41 6 / 3 / 18
verify_password 6 / 3 / 77 8 / 3 / 49

🤖 Generated with Claude Code

dominion525 and others added 2 commits October 25, 2026 04:59
…t took

- Test the key size of each algId by default, of Standard AES with the AES flag and of NonStandard AES
- Test the messages of the errors for an unknown algId or version, a short EncryptionInfo and one without the CryptoAPI flag

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ns, to make it easier to read

- Decrypt AES-CBC and AES-ECB with a function for each that chooses the cipher by the key length, used by the four functions that each had the same match
- Read the EncryptionHeader, and the AES key size when keySize is 0, with one function each
- Split the version check of the EncryptionInfo into functions that cut it out, read the CryptoAPI versions and read RC4
- Make the loop that reads the elements of Agile XML and the reading of attributes functions, and shorten the derivation of the three keys
- Keep the kinds and messages of the errors

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Coverage

For 919732b.

Filename                       Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
jetdb-cli/src/export.rs            108                11    89.81%           5                 0   100.00%          66                 6    90.91%           0                 0         -
jetdb-cli/src/form.rs              254                24    90.55%          19                 5    73.68%         152                 9    94.08%           0                 0         -
jetdb-cli/src/macro_cmd.rs         151                11    92.72%          11                 2    81.82%          81                 5    93.83%           0                 0         -
jetdb-cli/src/main.rs              864                38    95.60%          70                 2    97.14%         549                25    95.45%           0                 0         -
jetdb-cli/src/prop.rs              308                15    95.13%          33                 2    93.94%         186                10    94.62%           0                 0         -
jetdb-cli/src/query.rs              80                 4    95.00%           5                 0   100.00%          51                 1    98.04%           0                 0         -
jetdb-cli/src/vba.rs                74                 4    94.59%           5                 0   100.00%          47                 1    97.87%           0                 0         -
jetdb-wasm/src/lib.rs             3871                95    97.55%         252                 4    98.41%        2031                22    98.92%           0                 0         -
jetdb/src/catalog.rs               531                14    97.36%          41                 0   100.00%         304                 7    97.70%           0                 0         -
jetdb/src/complex.rs               917                32    96.51%          73                 0   100.00%         607                15    97.53%           0                 0         -
jetdb/src/crypto.rs               2300               112    95.13%         127                10    92.13%        1315                60    95.44%           0                 0         -
jetdb/src/csv.rs                   810                23    97.16%          65                 0   100.00%         453                 6    98.68%           0                 0         -
jetdb/src/data.rs                 4542               177    96.10%         254                 3    98.82%        2549               108    95.76%           0                 0         -
jetdb/src/ddl/access.rs             70                 0   100.00%           7                 0   100.00%          46                 0   100.00%           0                 0         -
jetdb/src/ddl/mod.rs              2777                 8    99.71%         199                 2    98.99%        1503                 6    99.60%           0                 0         -
jetdb/src/ddl/mysql.rs              70                 0   100.00%           7                 0   100.00%          46                 0   100.00%           0                 0         -
jetdb/src/ddl/postgres.rs           71                 0   100.00%           7                 0   100.00%          46                 0   100.00%           0                 0         -
jetdb/src/ddl/sqlite.rs             69                 0   100.00%           7                 0   
8000
100.00%          48                 0   100.00%           0                 0         -
jetdb/src/encoding.rs              284                 0   100.00%          30                 0   100.00%         153                 0   100.00%           0                 0         -
jetdb/src/file.rs                 1914                67    96.50%         110                 0   100.00%        1042                26    97.50%           0                 0         -
jetdb/src/form.rs                 3273               150    95.42%         233                10    95.71%        1773                69    96.11%           0                 0         -
jetdb/src/form2000.rs              762                21    97.24%          56                 1    98.21%         402                 4    99.00%           0                 0         -
jetdb/src/format.rs                620                 2    99.68%          41                 0   100.00%         408                 2    99.51%           0                 0         -
jetdb/src/lib.rs                     3                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
jetdb/src/macro_action.rs          299                19    93.65%          27                 3    88.89%         165                24    85.45%           0                 0         -
jetdb/src/macro_def.rs            2350                98    95.83%         179                 9    94.97%        1522                46    96.98%           0                 0         -
jetdb/src/macro_text.rs            783                24    96.93%          49                 2    95.92%         437                20    95.42%           0                 0         -
jetdb/src/map.rs                   416                13    96.88%          27                 0   100.00%         221                 5    97.74%           0                 0         -
jetdb/src/money.rs                 286                 0   100.00%          26                 0   100.00%         189                 0   100.00%           0                 0         -
jetdb/src/prop.rs                 1414                56    96.04%          88                 8    90.91%         744                63    91.53%           0                 0         -
jetdb/src/query.rs                2625                71    97.30%         187                 1    99.47%        1644                35    97.87%           0                 0         -
jetdb/src/relationship.rs          302                27    91.06%          12                 0   100.00%         187                17    90.91%           0                 0         -
jetdb/src/save_as_text.rs          574                27    95.30%          52                 3    94.23%         341                27    92.08%           0                 0         -
jetdb/src/storage.rs               596                46    92.28%          26                 1    96.15%         316                24    92.41%           0                 0         -
jetdb/src/table.rs                1589                61    96.16%          95                 2    97.89%         939                18    98.08%           0                 0         -
jetdb/src/timestamp.rs             413                 0   100.00%          43                 0   100.00%         232                 0   100.00%           0                 0         -
jetdb/src/vba.rs                   634                65    89.75%          54                16    70.37%         361                60    83.38%           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                            37004              1315    96.45%        2523                86    96.59%       21159               721    96.59%           0                 0         -

@dominion525
dominion525 merged commit 051a102 into main Oct 25, 2026
11 checks passed
@dominion525
dominion525 deleted the refactor/crypto branch October 25, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0