Skip to content

Split NativeGrep::matchFile and the RNP locateKey - #2426

Merged
annejan merged 1 commit into
mainfrom
refactor/complexity-2157-b5
Dec 1, 2026
Merged

annejan merged 1 commit into
mainfrom
refactor/complexity-2157-b5

Conversation

@annejan

@annejan annejan commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Fifth batch for #2157; the code and comments move into file-local helpers (anonymous namespace, full Doxygen blocks), no behaviour change.

  • NativeGrep::matchFile (CCN 25 → 7):
    • decryptForSearch(): read without following a link, capped, gpg on stdin, decoded as before;
    • previewOfMatch(): the OTP marker, the password mark, a short line, or a window that keeps a field's name;
    • windowAround(): where that window starts and ends, never half a surrogate pair.
  • locateKey in rnpcrypto.cpp (CCN 24 → 14):
    • locateExactKey(): a fingerprint or long key ID, and why it cannot be used;
    • primariesNamedBy(): short key ID, e-mail address, whole then partial user ID. Each branch returns directly instead of assigning.

Every helper is below CCN 15. No tr() strings are involved (rnpcrypto.cpp reasons are untranslated QStringLiterals, as before).

Test plan

  • Built with CONFIG+=rnp; full make check in a scratch HOME/GNUPGHOME: 37 suites (tst_rnpcrypto and tst_grepsearchcontroller included), 2,079 passed, 0 failed
  • doxygen Doxyfile prints no warnings
  • clang-format clean

Part of #2157.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved search of encrypted files, including handling read or decryption failures without showing incomplete results.
    • Search previews continue to hide OTP secrets and correctly handle password fields and text boundaries.
    • Improved recipient key selection for exact IDs and email addresses; ambiguous matches are rejected, and unavailable or unusable keys produce a specific failure.

Fifth batch for #2157 (lizard CCN 25 and 24). The code and its comments
move into file-local helpers:

- nativegrep.cpp: decryptForSearch() (read without following a link,
  capped, gpg on stdin, decoded), previewOfMatch() (the OTP marker, the
  password mark, a short line, or a window that keeps a field's name)
  and windowAround() (where that window starts and ends, never half a
  surrogate pair).
- rnpcrypto.cpp: locateExactKey() (a fingerprint or long key ID, and why
  it cannot be used) and primariesNamedBy() (short key ID, e-mail
  address, whole then partial user ID); its branches return directly.

No behaviour change. matchFile 25 -> 7, locateKey 24 -> 14; every helper
is below 15.

Part of #2157.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anne Jan Brouwer <[email protected]>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PR extracts decryption and preview-generation helpers from NativeGrep::matchFile. It also separates exact key lookup and recipient matching into helpers used by locateKey.

Changes: Native search

Layer / File(s) Summary
Ciphertext decryption and match integration
src/nativegrep.cpp
decryptForSearch reads ciphertext through the regular-file or store-contained reader, applies the ciphertext cap, and decrypts with GPG. matchFile uses the returned plaintext and returns no matches when it is empty.
Matching-line previews
src/nativegrep.cpp
windowAround selects bounded preview windows without splitting surrogate pairs. previewOfMatch handles OTP markers, password matches, short lines, and long-line previews while preserving field-name and secret-hiding behavior.

RNP key lookup

Layer / File(s) Summary
Key lookup helpers and routing
src/rnpcrypto.cpp
locateExactKey validates exact fingerprint and long-key-ID matches for the requested usage. primariesNamedBy finds eligible candidates by short key ID, email mailbox, or user ID. locateKey delegates to these helpers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related issues

  • Issue 2157 — This PR splits two functions listed in the issue: NativeGrep::matchFile and locateKey.

Possibly related PRs

  • IJHack/QtPass#2331 — Both changes use the link-safe file-reading behavior in the native search path.
  • IJHack/QtPass#2081 — windowAround() preserves the surrogate-pair-safe preview-window behavior.

Suggested reviewers: nogeenhenk

Merge Risk: Minimal · up to 06ccd

This refactor splits large functions in the native search and RNP key lookup code into smaller helpers without intending any behavior change. No concrete regression was found, and the reported test run passed, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Split NativeGrep::matchFile and the RNP locateKey" names the two main changes. The raw summary and objectives confirm that matchFile now delegates to decryptForSearch, windowAround, and pre…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Split NativeGrep::matchFile and the RNP locateKey" names the two main changes. The raw summary and objectives confirm that matchFile now delegates to decryptForSearch, windowAround, and previewOfMatch, and that locateKey delegates to locateExactKey and primariesNamedBy. The title is specific and matches the changeset. It describes a refactor, which fits the stated no-behavior-change intent.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each secret line,
And keeps the preview bounds in line.
GPG returns the text to view,
While key lookups take paths anew.
The carrots wait; the helpers hop,
Then neatly bring the search to stop.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 0e1fefa3-4c37-40aa-bd8d-e742883019cc
Commits

Reviewing files that changed from the base of the PR and between 328c919 and 06ccd66.

Files selected for processing: 2

  • src/nativegrep.cpp
  • src/rnpcrypto.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 94.549% (+0.003%) from 94.546% — refactor/complexity-2157-b5 into main

@nogeenhenk nogeenhenk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 06ccd66. The fifth refactor for #2157; only the structure changes.

  • locateKey: locateExactKey() is the old exact-key branch unchanged, and primariesNamedBy() returns from each branch what the old code assigned (short key ID, address, whole then partial user ID). The "more than one key" check stays in locateKey.
  • NativeGrep::matchFile: decryptForSearch() returns empty in every case the old code returned early (read failure, rc != 0, empty plaintext), and previewOfMatch() / windowAround() give the same result string in each of the old continue branches, the OTP marker and the password mark included.
  • No tr() strings are involved.

One cosmetic nit: the old comment @brief Decrypt one .gpg file and return lines matching rx. now sits above namespace { instead of above NativeGrep::matchFile(). Doxygen does not warn about it, but it describes the function further down.


Generated by Claude Code

@annejan
annejan merged commit 30c9f40 into main Dec 1, 2026
33 checks passed
@annejan
annejan deleted the refactor/complexity-2157-b5 branch December 1, 2026 01:32
@annejan annejan mentioned this pull request Dec 1, 2026
29 of 40 tasks
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.

3 participants