| 1 | # Copyright © 2022-2024 Guillem Jover <guillem@debian.org> | ||||||||||
| 2 | # | ||||||||||
| 3 | # This program is free software; you can redistribute it and/or modify | ||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||
| 5 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||
| 6 | # (at your option) any later version. | ||||||||||
| 7 | # | ||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||
| 12 | # | ||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||
| 14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||||||
| 15 | |||||||||||
| 16 | =encoding utf8 | ||||||||||
| 17 | |||||||||||
| 18 | =head1 NAME | ||||||||||
| 19 | |||||||||||
| 20 | Dpkg::OpenPGP::ErrorCodes - OpenPGP error codes | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | This module provides error codes handling to be used by the various | ||||||||||
| 25 | OpenPGP backends. | ||||||||||
| 26 | |||||||||||
| 27 | B<Note>: This is a private module, its API can change at any time. | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | package Dpkg::OpenPGP::ErrorCodes 0.01; | ||||||||||
| 32 | |||||||||||
| 33 | 6 | ▶ | use v5.36; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 6 | our @EXPORT = qw( | |||||||||
| 36 | OPENPGP_OK | ||||||||||
| 37 | OPENPGP_NO_SIG | ||||||||||
| 38 | OPENPGP_MISSING_ARG | ||||||||||
| 39 | OPENPGP_UNSUPPORTED_OPTION | ||||||||||
| 40 | OPENPGP_BAD_DATA | ||||||||||
| 41 | OPENPGP_EXPECTED_TEXT | ||||||||||
| 42 | OPENPGP_OUTPUT_EXISTS | ||||||||||
| 43 | OPENPGP_MISSING_INPUT | ||||||||||
| 44 | OPENPGP_KEY_IS_PROTECTED | ||||||||||
| 45 | OPENPGP_UNSUPPORTED_SUBCMD | ||||||||||
| 46 | OPENPGP_UNSUPPORTED_SPECIAL_PREFIX | ||||||||||
| 47 | OPENPGP_AMBIGUOUS_INPUT | ||||||||||
| 48 | OPENPGP_KEY_CANNOT_SIGN | ||||||||||
| 49 | OPENPGP_INCOMPATIBLE_OPTIONS | ||||||||||
| 50 | OPENPGP_NO_HW_KEY_FOUND | ||||||||||
| 51 | OPENPGP_HW_KEY_FAILURE | ||||||||||
| 52 | |||||||||||
| 53 | OPENPGP_MISSING_CMD | ||||||||||
| 54 | OPENPGP_NEEDS_KEYSTORE | ||||||||||
| 55 | OPENPGP_CMD_CANNOT_SIGN | ||||||||||
| 56 | OPENPGP_MISSING_KEYRINGS | ||||||||||
| 57 | |||||||||||
| 58 | openpgp_errorcode_to_string | ||||||||||
| 59 | ); | ||||||||||
| 60 | |||||||||||
| 61 | 6 | ▶ | use Exporter qw(import); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | |||||||||||
| 63 | 6 | ▶ | use Dpkg::Gettext; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 64 | |||||||||||
| 65 | # Error codes based on: | ||||||||||
| 66 | # https://ietf.org/archive/id/draft-dkg-openpgp-stateless-cli-10.html#section-7 | ||||||||||
| 67 | # | ||||||||||
| 68 | # Local error codes use a negative number, as that should not conflict with | ||||||||||
| 69 | # the SOP exit codes. | ||||||||||
| 70 | |||||||||||
| 71 | 6 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 72 | 6 | OPENPGP_OK => 0, | |||||||||
| 73 | OPENPGP_NO_SIG => 3, | ||||||||||
| 74 | OPENPGP_MISSING_ARG => 19, | ||||||||||
| 75 | OPENPGP_UNSUPPORTED_OPTION => 37, | ||||||||||
| 76 | OPENPGP_BAD_DATA => 41, | ||||||||||
| 77 | OPENPGP_EXPECTED_TEXT => 53, | ||||||||||
| 78 | OPENPGP_OUTPUT_EXISTS => 59, | ||||||||||
| 79 | OPENPGP_MISSING_INPUT => 61, | ||||||||||
| 80 | OPENPGP_KEY_IS_PROTECTED => 67, | ||||||||||
| 81 | OPENPGP_UNSUPPORTED_SUBCMD => 69, | ||||||||||
| 82 | OPENPGP_UNSUPPORTED_SPECIAL_PREFIX => 71, | ||||||||||
| 83 | OPENPGP_AMBIGUOUS_INPUT => 73, | ||||||||||
| 84 | OPENPGP_KEY_CANNOT_SIGN => 79, | ||||||||||
| 85 | OPENPGP_INCOMPATIBLE_OPTIONS => 83, | ||||||||||
| 86 | OPENPGP_NO_HW_KEY_FOUND => 97, | ||||||||||
| 87 | OPENPGP_HW_KEY_FAILURE => 101, | ||||||||||
| 88 | |||||||||||
| 89 | OPENPGP_MISSING_CMD => -1, | ||||||||||
| 90 | OPENPGP_NEEDS_KEYSTORE => -2, | ||||||||||
| 91 | OPENPGP_CMD_CANNOT_SIGN => -3, | ||||||||||
| 92 | OPENPGP_MISSING_KEYRINGS => -4, | ||||||||||
| 93 | 6 | }; | |||||||||
| 94 | |||||||||||
| 95 | 6 | my %code2error = ( | |||||||||
| 96 | OPENPGP_OK() => N_('success'), | ||||||||||
| 97 | OPENPGP_NO_SIG() => N_('no acceptable signature found'), | ||||||||||
| 98 | OPENPGP_MISSING_ARG() => N_('missing required argument'), | ||||||||||
| 99 | OPENPGP_UNSUPPORTED_OPTION() => N_('unsupported option'), | ||||||||||
| 100 | OPENPGP_BAD_DATA() => N_('invalid data type'), | ||||||||||
| 101 | OPENPGP_EXPECTED_TEXT() => N_('non-text input where text expected'), | ||||||||||
| 102 | OPENPGP_OUTPUT_EXISTS() => N_('output file already exists'), | ||||||||||
| 103 | OPENPGP_MISSING_INPUT() => N_('input file does not exist'), | ||||||||||
| 104 | OPENPGP_KEY_IS_PROTECTED() => N_('cannot unlock password-protected key'), | ||||||||||
| 105 | OPENPGP_UNSUPPORTED_SUBCMD() => N_('unsupported subcommand'), | ||||||||||
| 106 | OPENPGP_UNSUPPORTED_SPECIAL_PREFIX() => N_('unknown special designator in indirect parameter'), | ||||||||||
| 107 | OPENPGP_AMBIGUOUS_INPUT() => N_('special designator in indirect parameter is an existing file'), | ||||||||||
| 108 | OPENPGP_KEY_CANNOT_SIGN() => N_('key is not signature-capable'), | ||||||||||
| 109 | OPENPGP_INCOMPATIBLE_OPTIONS() => N_('mutually exclusive options'), | ||||||||||
| 110 | OPENPGP_NO_HW_KEY_FOUND() => N_('cannot identify hardware device for hardware-backed secret keys'), | ||||||||||
| 111 | OPENPGP_HW_KEY_FAILURE() => N_('cannot perform operation on hardware-backed secret key'), | ||||||||||
| 112 | |||||||||||
| 113 | OPENPGP_MISSING_CMD() => N_('missing OpenPGP implementation'), | ||||||||||
| 114 | OPENPGP_NEEDS_KEYSTORE() => N_('specified key needs a keystore'), | ||||||||||
| 115 | OPENPGP_CMD_CANNOT_SIGN() => N_('OpenPGP backend command cannot sign'), | ||||||||||
| 116 | OPENPGP_MISSING_KEYRINGS() => N_('missing OpenPGP keyrings'), | ||||||||||
| 117 | ); | ||||||||||
| 118 | |||||||||||
| 119 | sub openpgp_errorcode_to_string | ||||||||||
| 120 | 0 | ▶ | { | ||||||||
|
Subroutine
openpgp_errorcode_to_string: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 121 | 0 | my $code = shift; | |||||||||
| 122 | |||||||||||
| 123 | 0 | ▶ | return gettext($code2error{$code}) if exists $code2error{$code}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | return sprintf g_('error code %d'), $code; | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | =head1 CHANGES | ||||||||||
| 128 | |||||||||||
| 129 | =head2 Version 0.xx | ||||||||||
| 130 | |||||||||||
| 131 | This is a private module. | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||
| 134 | |||||||||||
| 135 | 6 | 1; | |||||||||