<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Copyright Â© 2022 Guillem Jover &lt;guillem@debian.org&gt;
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see &lt;https://www.gnu.org/licenses/&gt;.

package Dpkg::OpenPGP::ErrorCodes;

use strict;
use warnings;

our $VERSION = '0.01';
our @EXPORT = qw(
    OPENPGP_OK
    OPENPGP_NO_SIG
    OPENPGP_MISSING_ARG
    OPENPGP_UNSUPPORTED_OPTION
    OPENPGP_BAD_DATA
    OPENPGP_EXPECTED_TEXT
    OPENPGP_OUTPUT_EXISTS
    OPENPGP_MISSING_INPUT
    OPENPGP_KEY_IS_PROTECTED
    OPENPGP_UNSUPPORTED_SUBCMD
    OPENPGP_KEY_CANNOT_SIGN

    OPENPGP_MISSING_CMD
    OPENPGP_NEEDS_KEYSTORE

    openpgp_errorcode_to_string
);

use Exporter qw(import);

use Dpkg::Gettext;

# Error codes based on
# https://ietf.org/archive/id/draft-dkg-openpgp-stateless-cli-04.html#section-6
#
# Local error codes use a negative number, as that should not conflict with
# the SOP exit codes.

use constant {
    OPENPGP_OK =&gt; 0,
    OPENPGP_NO_SIG =&gt; 3,
    OPENPGP_MISSING_ARG =&gt; 19,
    OPENPGP_UNSUPPORTED_OPTION =&gt; 37,
    OPENPGP_BAD_DATA =&gt; 41,
    OPENPGP_EXPECTED_TEXT =&gt; 53,
    OPENPGP_OUTPUT_EXISTS =&gt; 59,
    OPENPGP_MISSING_INPUT =&gt; 61,
    OPENPGP_KEY_IS_PROTECTED =&gt; 67,
    OPENPGP_UNSUPPORTED_SUBCMD =&gt; 69,
    OPENPGP_KEY_CANNOT_SIGN =&gt; 79,

    OPENPGP_MISSING_CMD =&gt; -1,
    OPENPGP_NEEDS_KEYSTORE =&gt; -2,
};

my %code2error = (
    OPENPGP_OK() =&gt; N_('success'),
    OPENPGP_NO_SIG() =&gt; N_('no acceptable signature found'),
    OPENPGP_MISSING_ARG() =&gt; N_('missing required argument'),
    OPENPGP_UNSUPPORTED_OPTION() =&gt; N_('unsupported option'),
    OPENPGP_BAD_DATA() =&gt; N_('invalid data type'),
    OPENPGP_EXPECTED_TEXT() =&gt; N_('non-text input where text expected'),
    OPENPGP_OUTPUT_EXISTS() =&gt; N_('output file already exists'),
    OPENPGP_MISSING_INPUT() =&gt; N_('input file does not exist'),
    OPENPGP_KEY_IS_PROTECTED() =&gt; N_('cannot unlock password-protected key'),
    OPENPGP_UNSUPPORTED_SUBCMD() =&gt; N_('unsupported subcommand'),
    OPENPGP_KEY_CANNOT_SIGN() =&gt; N_('key is not signature-capable'),

    OPENPGP_MISSING_CMD() =&gt; N_('missing OpenPGP implementation'),
    OPENPGP_NEEDS_KEYSTORE() =&gt; N_('specified key needs a keystore'),
);

sub openpgp_errorcode_to_string
{
    my $code = shift;

    return gettext($code2error{$code}) if exists $code2error{$code};
    return sprintf g_('error code %d'), $code;
}

1;
</pre></body></html>