| File: | Dpkg/OpenPGP/Backend.pm |
| Coverage: | 59.2% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | # Copyright © 2017, 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 | =encoding utf8 | ||||||
| 17 | |||||||
| 18 - 29 | =head1 NAME Dpkg::OpenPGP::Backend - OpenPGP backend base class =head1 DESCRIPTION This module provides an OpenPGP backend base class that specific implementations should inherit from. B<Note>: This is a private module, its API can change at any time. =cut | ||||||
| 30 | |||||||
| 31 | package Dpkg::OpenPGP::Backend 0.01; | ||||||
| 32 | |||||||
| 33 | 216 216 216 | 50079 213 3003 | use strict; | ||||
| 34 | 216 216 216 | 495 75 5481 | use warnings; | ||||
| 35 | |||||||
| 36 | 216 216 216 | 363 228 6294 | use List::Util qw(first); | ||||
| 37 | |||||||
| 38 | 216 216 216 | 501 72 4443 | use Dpkg::Path qw(find_command); | ||||
| 39 | 216 216 216 | 363 282 59499 | use Dpkg::OpenPGP::ErrorCodes; | ||||
| 40 | |||||||
| 41 | sub DEFAULT_CMDV { | ||||||
| 42 | 423 | 0 | 644 | return []; | |||
| 43 | } | ||||||
| 44 | |||||||
| 45 | sub DEFAULT_CMDSTORE { | ||||||
| 46 | 423 | 0 | 504 | return []; | |||
| 47 | } | ||||||
| 48 | |||||||
| 49 | sub DEFAULT_CMD { | ||||||
| 50 | 0 | 0 | 0 | return []; | |||
| 51 | } | ||||||
| 52 | |||||||
| 53 | sub _detect_cmd { | ||||||
| 54 | 2205 | 3614 | my ($cmd, $default) = @_; | ||||
| 55 | |||||||
| 56 | 2205 | 9848 | if (! defined $cmd || $cmd eq 'auto') { | ||||
| 57 | 1686 840 1686 | 6007 2658 5866 | return first { find_command($_) } @{$default}; | ||||
| 58 | } else { | ||||||
| 59 | 519 | 1858 | return find_command($cmd); | ||||
| 60 | } | ||||||
| 61 | } | ||||||
| 62 | |||||||
| 63 | sub new { | ||||||
| 64 | 735 | 0 | 3379 | my ($this, %opts) = @_; | |||
| 65 | 735 | 5151 | my $class = ref($this) || $this; | ||||
| 66 | |||||||
| 67 | 735 | 1166 | my $self = {}; | ||||
| 68 | 735 | 1140 | bless $self, $class; | ||||
| 69 | |||||||
| 70 | 735 | 3641 | $self->{cmdv} = _detect_cmd($opts{cmdv}, $self->DEFAULT_CMDV()); | ||||
| 71 | 735 | 3343 | $self->{cmdstore} = _detect_cmd($opts{cmdstore}, $self->DEFAULT_CMDSTORE()); | ||||
| 72 | 735 | 2577 | $self->{cmd} = _detect_cmd($opts{cmd}, $self->DEFAULT_CMD()); | ||||
| 73 | |||||||
| 74 | 735 | 4595 | return $self; | ||||
| 75 | } | ||||||
| 76 | |||||||
| 77 | sub has_backend_cmd { | ||||||
| 78 | 513 | 0 | 619 | my $self = shift; | |||
| 79 | |||||||
| 80 | 513 | 1856 | return defined $self->{cmd}; | ||||
| 81 | } | ||||||
| 82 | |||||||
| 83 | sub has_verify_cmd { | ||||||
| 84 | 423 | 0 | 584 | my $self = shift; | |||
| 85 | |||||||
| 86 | 423 | 773 | return defined $self->{cmd}; | ||||
| 87 | } | ||||||
| 88 | |||||||
| 89 | sub has_keystore { | ||||||
| 90 | 0 | 0 | 0 | my $self = shift; | |||
| 91 | |||||||
| 92 | 0 | 0 | return 0; | ||||
| 93 | } | ||||||
| 94 | |||||||
| 95 | sub can_use_key { | ||||||
| 96 | 306 | 0 | 416 | my ($self, $key) = @_; | |||
| 97 | |||||||
| 98 | 306 | 890 | return $self->has_keystore() if $key->needs_keystore(); | ||||
| 99 | 306 | 827 | return 1; | ||||
| 100 | } | ||||||
| 101 | |||||||
| 102 | sub get_trusted_keyrings { | ||||||
| 103 | 0 | 0 | my $self = shift; | ||||
| 104 | |||||||
| 105 | 0 | return (); | |||||
| 106 | } | ||||||
| 107 | |||||||
| 108 | sub armor { | ||||||
| 109 | 0 | 0 | my ($self, $type, $in, $out) = @_; | ||||
| 110 | |||||||
| 111 | 0 | return OPENPGP_UNSUPPORTED_SUBCMD; | |||||
| 112 | } | ||||||
| 113 | |||||||
| 114 | sub dearmor { | ||||||
| 115 | 0 | 0 | my ($self, $type, $in, $out) = @_; | ||||
| 116 | |||||||
| 117 | 0 | return OPENPGP_UNSUPPORTED_SUBCMD; | |||||
| 118 | } | ||||||
| 119 | |||||||
| 120 | sub inline_verify { | ||||||
| 121 | 0 | 0 | my ($self, $inlinesigned, $data, @certs) = @_; | ||||
| 122 | |||||||
| 123 | 0 | return OPENPGP_UNSUPPORTED_SUBCMD; | |||||
| 124 | } | ||||||
| 125 | |||||||
| 126 | sub verify { | ||||||
| 127 | 0 | 0 | my ($self, $data, $sig, @certs) = @_; | ||||
| 128 | |||||||
| 129 | 0 | return OPENPGP_UNSUPPORTED_SUBCMD; | |||||
| 130 | } | ||||||
| 131 | |||||||
| 132 | sub inline_sign { | ||||||
| 133 | 0 | 0 | my ($self, $data, $inlinesigned, $key) = @_; | ||||
| 134 | |||||||
| 135 | 0 | return OPENPGP_UNSUPPORTED_SUBCMD; | |||||
| 136 | } | ||||||
| 137 | |||||||
| 138 - 144 | =head1 CHANGES =head2 Version 0.xx This is a private module. =cut | ||||||
| 145 | |||||||
| 146 | 1; | ||||||