File: | Dpkg/OpenPGP/ErrorCodes.pm |
Coverage: | 74.1% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | # Copyright © 2022 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 | package Dpkg::OpenPGP::ErrorCodes; | ||||||
17 | |||||||
18 | 44 44 44 | 88 44 484 | use strict; | ||||
19 | 44 44 44 | 88 0 1657 | use warnings; | ||||
20 | |||||||
21 | our $VERSION = '0.01'; | ||||||
22 | our @EXPORT = qw( | ||||||
23 | OPENPGP_OK | ||||||
24 | OPENPGP_NO_SIG | ||||||
25 | OPENPGP_MISSING_ARG | ||||||
26 | OPENPGP_UNSUPPORTED_OPTION | ||||||
27 | OPENPGP_BAD_DATA | ||||||
28 | OPENPGP_EXPECTED_TEXT | ||||||
29 | OPENPGP_OUTPUT_EXISTS | ||||||
30 | OPENPGP_MISSING_INPUT | ||||||
31 | OPENPGP_KEY_IS_PROTECTED | ||||||
32 | OPENPGP_UNSUPPORTED_SUBCMD | ||||||
33 | OPENPGP_KEY_CANNOT_SIGN | ||||||
34 | |||||||
35 | OPENPGP_MISSING_CMD | ||||||
36 | OPENPGP_NEEDS_KEYSTORE | ||||||
37 | |||||||
38 | openpgp_errorcode_to_string | ||||||
39 | ); | ||||||
40 | |||||||
41 | 44 44 44 | 88 0 578 | use Exporter qw(import); | ||||
42 | |||||||
43 | 44 44 44 | 44 44 1710 | use Dpkg::Gettext; | ||||
44 | |||||||
45 | # Error codes based on | ||||||
46 | # https://ietf.org/archive/id/draft-dkg-openpgp-stateless-cli-04.html#section-6 | ||||||
47 | # | ||||||
48 | # Local error codes use a negative number, as that should not conflict with | ||||||
49 | # the SOP exit codes. | ||||||
50 | |||||||
51 | use constant { | ||||||
52 | 44 | 6021 | OPENPGP_OK => 0, | ||||
53 | OPENPGP_NO_SIG => 3, | ||||||
54 | OPENPGP_MISSING_ARG => 19, | ||||||
55 | OPENPGP_UNSUPPORTED_OPTION => 37, | ||||||
56 | OPENPGP_BAD_DATA => 41, | ||||||
57 | OPENPGP_EXPECTED_TEXT => 53, | ||||||
58 | OPENPGP_OUTPUT_EXISTS => 59, | ||||||
59 | OPENPGP_MISSING_INPUT => 61, | ||||||
60 | OPENPGP_KEY_IS_PROTECTED => 67, | ||||||
61 | OPENPGP_UNSUPPORTED_SUBCMD => 69, | ||||||
62 | OPENPGP_KEY_CANNOT_SIGN => 79, | ||||||
63 | |||||||
64 | OPENPGP_MISSING_CMD => -1, | ||||||
65 | OPENPGP_NEEDS_KEYSTORE => -2, | ||||||
66 | 44 44 | 94 44 | }; | ||||
67 | |||||||
68 | my %code2error = ( | ||||||
69 | OPENPGP_OK() => N_('success'), | ||||||
70 | OPENPGP_NO_SIG() => N_('no acceptable signature found'), | ||||||
71 | OPENPGP_MISSING_ARG() => N_('missing required argument'), | ||||||
72 | OPENPGP_UNSUPPORTED_OPTION() => N_('unsupported option'), | ||||||
73 | OPENPGP_BAD_DATA() => N_('invalid data type'), | ||||||
74 | OPENPGP_EXPECTED_TEXT() => N_('non-text input where text expected'), | ||||||
75 | OPENPGP_OUTPUT_EXISTS() => N_('output file already exists'), | ||||||
76 | OPENPGP_MISSING_INPUT() => N_('input file does not exist'), | ||||||
77 | OPENPGP_KEY_IS_PROTECTED() => N_('cannot unlock password-protected key'), | ||||||
78 | OPENPGP_UNSUPPORTED_SUBCMD() => N_('unsupported subcommand'), | ||||||
79 | OPENPGP_KEY_CANNOT_SIGN() => N_('key is not signature-capable'), | ||||||
80 | |||||||
81 | OPENPGP_MISSING_CMD() => N_('missing OpenPGP implementation'), | ||||||
82 | OPENPGP_NEEDS_KEYSTORE() => N_('specified key needs a keystore'), | ||||||
83 | ); | ||||||
84 | |||||||
85 | sub openpgp_errorcode_to_string | ||||||
86 | { | ||||||
87 | 0 | 0 | my $code = shift; | ||||
88 | |||||||
89 | 0 | return gettext($code2error{$code}) if exists $code2error{$code}; | |||||
90 | 0 | return sprintf g_('error code %d'), $code; | |||||
91 | } | ||||||
92 | |||||||
93 | 1; |