File: | Dpkg/OpenPGP/ErrorCodes.pm |
Coverage: | 74.1% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
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 - 29 | =head1 NAME Dpkg::OpenPGP::ErrorCodes - OpenPGP error codes =head1 DESCRIPTION This module provides error codes handling to be used by the various OpenPGP backends. B<Note>: This is a private module, its API can change at any time. =cut | ||||||
30 | |||||||
31 | package Dpkg::OpenPGP::ErrorCodes 0.01; | ||||||
32 | |||||||
33 | 216 216 216 | 642 147 3636 | use strict; | ||||
34 | 216 216 216 | 438 141 11484 | use warnings; | ||||
35 | |||||||
36 | our @EXPORT = qw( | ||||||
37 | OPENPGP_OK | ||||||
38 | OPENPGP_NO_SIG | ||||||
39 | OPENPGP_MISSING_ARG | ||||||
40 | OPENPGP_UNSUPPORTED_OPTION | ||||||
41 | OPENPGP_BAD_DATA | ||||||
42 | OPENPGP_EXPECTED_TEXT | ||||||
43 | OPENPGP_OUTPUT_EXISTS | ||||||
44 | OPENPGP_MISSING_INPUT | ||||||
45 | OPENPGP_KEY_IS_PROTECTED | ||||||
46 | OPENPGP_UNSUPPORTED_SUBCMD | ||||||
47 | OPENPGP_UNSUPPORTED_SPECIAL_PREFIX | ||||||
48 | OPENPGP_AMBIGUOUS_INPUT | ||||||
49 | OPENPGP_KEY_CANNOT_SIGN | ||||||
50 | OPENPGP_INCOMPATIBLE_OPTIONS | ||||||
51 | OPENPGP_NO_HW_KEY_FOUND | ||||||
52 | OPENPGP_HW_KEY_FAILURE | ||||||
53 | |||||||
54 | OPENPGP_MISSING_CMD | ||||||
55 | OPENPGP_NEEDS_KEYSTORE | ||||||
56 | OPENPGP_CMD_CANNOT_SIGN | ||||||
57 | |||||||
58 | openpgp_errorcode_to_string | ||||||
59 | ); | ||||||
60 | |||||||
61 | 216 216 216 | 570 216 4731 | use Exporter qw(import); | ||||
62 | |||||||
63 | 216 216 216 | 429 144 12897 | use Dpkg::Gettext; | ||||
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 | use constant { | ||||||
72 | 216 | 50901 | 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 | 216 216 | 576 213 | }; | ||||
93 | |||||||
94 | my %code2error = ( | ||||||
95 | OPENPGP_OK() => N_('success'), | ||||||
96 | OPENPGP_NO_SIG() => N_('no acceptable signature found'), | ||||||
97 | OPENPGP_MISSING_ARG() => N_('missing required argument'), | ||||||
98 | OPENPGP_UNSUPPORTED_OPTION() => N_('unsupported option'), | ||||||
99 | OPENPGP_BAD_DATA() => N_('invalid data type'), | ||||||
100 | OPENPGP_EXPECTED_TEXT() => N_('non-text input where text expected'), | ||||||
101 | OPENPGP_OUTPUT_EXISTS() => N_('output file already exists'), | ||||||
102 | OPENPGP_MISSING_INPUT() => N_('input file does not exist'), | ||||||
103 | OPENPGP_KEY_IS_PROTECTED() => N_('cannot unlock password-protected key'), | ||||||
104 | OPENPGP_UNSUPPORTED_SUBCMD() => N_('unsupported subcommand'), | ||||||
105 | OPENPGP_UNSUPPORTED_SPECIAL_PREFIX() => N_('unknown special designator in indirect parameter'), | ||||||
106 | OPENPGP_AMBIGUOUS_INPUT() => N_('special designator in indirect parameter is an existing file'), | ||||||
107 | OPENPGP_KEY_CANNOT_SIGN() => N_('key is not signature-capable'), | ||||||
108 | OPENPGP_INCOMPATIBLE_OPTIONS() => N_('mutually exclusive options'), | ||||||
109 | OPENPGP_NO_HW_KEY_FOUND() => N_('cannot identify hardware device for hardware-backed secret keys'), | ||||||
110 | OPENPGP_HW_KEY_FAILURE() => N_('cannot perform operation on hardware-backed secret key'), | ||||||
111 | |||||||
112 | OPENPGP_MISSING_CMD() => N_('missing OpenPGP implementation'), | ||||||
113 | OPENPGP_NEEDS_KEYSTORE() => N_('specified key needs a keystore'), | ||||||
114 | OPENPGP_CMD_CANNOT_SIGN() => N_('OpenPGP backend command cannot sign'), | ||||||
115 | ); | ||||||
116 | |||||||
117 | sub openpgp_errorcode_to_string | ||||||
118 | { | ||||||
119 | 0 | 0 | my $code = shift; | ||||
120 | |||||||
121 | 0 | return gettext($code2error{$code}) if exists $code2error{$code}; | |||||
122 | 0 | return sprintf g_('error code %d'), $code; | |||||
123 | } | ||||||
124 | |||||||
125 - 131 | =head1 CHANGES =head2 Version 0.xx This is a private module. =cut | ||||||
132 | |||||||
133 | 1; |