QtPass Developer documentation
QtPass test coverage
Current view: top level - src/processinfo.cpp (source / functions) Coverage Total Hit
Test: QtPass Lines: 100.0 % 5 5
Test Date: 2026-11-14 13:19:18 Functions: 100.0 % 2 2

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
       2              : // SPDX-License-Identifier: GPL-3.0-or-later
       3              : /**
       4              :  * @file
       5              :  * @brief The process table behind Enums::processInfo(); a missing row for a
       6              :  * new Enums::PROCESS value fails the build here.
       7              :  */
       8              : #include "processinfo.h"
       9              : #include <QString>
      10              : 
      11              : #include <array>
      12              : 
      13              : namespace Enums {
      14              : 
      15              : namespace {
      16              : 
      17              : /**
      18              :  * @brief The one table, indexed by PROCESS.
      19              :  *
      20              :  * `secret` is an allow list turned around: a process kind is silent until
      21              :  * someone decides its output is harmless. The static_assert below makes the
      22              :  * compiler ask that question for every value added to the enum.
      23              :  */
      24              : constexpr std::array kTable{
      25              :     ProcessInfo{"git init", false},   // GIT_INIT  // no-tr
      26              :     ProcessInfo{"git add", false},    // GIT_ADD  // no-tr
      27              :     ProcessInfo{"git commit", false}, // GIT_COMMIT  // no-tr
      28              :     ProcessInfo{"git rm", false},     // GIT_RM  // no-tr
      29              :     ProcessInfo{"git pull", false},   // GIT_PULL  // no-tr
      30              :     ProcessInfo{"git push", false},   // GIT_PUSH  // no-tr
      31              :     ProcessInfo{"", true},            // PASS_SHOW: the decrypted entry
      32              :     ProcessInfo{"pass insert",
      33              :                 true}, // PASS_INSERT: the entry being written  // no-tr
      34              :     ProcessInfo{"pass rm", false},       // PASS_REMOVE  // no-tr
      35              :     ProcessInfo{"pass init", false},     // PASS_INIT  // no-tr
      36              :     ProcessInfo{"gpg --gen-key", false}, // GPG_GENKEYS  // no-tr
      37              :     ProcessInfo{"pass mv", false},       // PASS_MOVE  // no-tr
      38              :     ProcessInfo{"pass cp", false},       // PASS_COPY  // no-tr
      39              :     ProcessInfo{"git mv", false},        // GIT_MOVE  // no-tr
      40              :     // ImitatePass::Copy literally invokes `git cp` (a git-extras
      41              :     // subcommand), so the label matches what is run. Stock-git users without
      42              :     // git-extras see the underlying "'cp' is not a git command" failure in
      43              :     // the process output panel.
      44              :     ProcessInfo{"git cp", false},   // GIT_COPY  // no-tr
      45              :     ProcessInfo{"pass grep", true}, // PASS_GREP: hits inside entries  // no-tr
      46              : };
      47              : 
      48              : // The extent comes from the rows, not from PROCESS_COUNT: a table declared
      49              : // as PROCESS_COUNT long would value-initialise a missing row into
      50              : // {nullptr, false}, and a new process kind would be broadcast as harmless.
      51              : static_assert(kTable.size() == static_cast<std::size_t>(PROCESS_COUNT),
      52              :               "every PROCESS needs a label and a secrecy decision");
      53              : 
      54              : constexpr ProcessInfo kNotAProcess{"", false};
      55              : 
      56              : } // namespace
      57              : 
      58          150 : auto processInfo(PROCESS pid) -> const ProcessInfo & {
      59          150 :   if (pid < 0 || pid >= PROCESS_COUNT) {
      60              :     return kNotAProcess;
      61              :   }
      62          145 :   return kTable.at(static_cast<std::size_t>(pid));
      63              : }
      64              : 
      65           30 : auto processLabel(PROCESS pid) -> QString {
      66           60 :   return QString::fromLatin1(processInfo(pid).label);
      67              : }
      68              : 
      69              : } // namespace Enums
        

Generated by: LCOV version 2.0-1