| 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 | =encoding utf8 | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | Dpkg::OpenPGP::KeyHandle - OpenPGP key handle support | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | This module provides a class to hold an OpenPGP key handle, as a way for | ||||||||||||||||||||
| 25 | the code to refer to a key in an independent way. | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | B<Note>: This is a private module, its API can change at any time. | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | package Dpkg::OpenPGP::KeyHandle 0.01; | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 6 | ▶ | use v5.36; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 6 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 6 | ▶ | use List::Util qw(any none); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 16 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||
| 39 | 16 | my ($this, %opts) = @_; | |||||||||||||||||||
| 40 | 16 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | my $self = { | ||||||||||||||||||||
| 43 | type => $opts{type} // 'auto', | ||||||||||||||||||||
| 44 | handle => $opts{handle}, | ||||||||||||||||||||
| 45 | 16 | ▶ | }; | ||||||||||||||||||
|
Condition50%1/2
$opts{"type"} // "auto"
MC/DC0%0/1
$opts{"type"} // "auto"
$opts{"type"}
Truth table50%1/2
A
A= $opts{"type"}
| |||||||||||||||||||||
| 46 | 16 | bless $self, $class; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 16 | $self->_sanitize(); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 16 | return $self; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 6 | my $keyid_regex = qr/^(?:0x)?([[:xdigit:]]+)$/; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 16 | ▶ | sub _sanitize { | ||||||||||||||||||
|
Subroutine
_sanitize: called CC=8 SCAR=21.1
| |||||||||||||||||||||
| 56 | 16 | my $self = shift; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 16 | my $type = $self->{type}; | |||||||||||||||||||
| 59 | 16 | ▶ | if ($type eq 'auto') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 5 | ▶ | if (-e $self->{handle}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | $type = 'keyfile'; | |||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||
| 63 | 5 | $type = 'autoid'; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 16 | ▶ | if ($type eq 'autoid') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 68 | 5 | ▶ | if ($self->{handle} =~ m/$keyid_regex/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 3 | $self->{handle} = $1; | |||||||||||||||||||
| 70 | 3 | $type = 'keyid'; | |||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||
| 72 | 2 | $type = 'userid'; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 5 | $self->{type} = $type; | |||||||||||||||||||
| 75 | } elsif ($type eq 'keyid') { | ||||||||||||||||||||
| 76 | 3 | ▶ | if ($self->{handle} =~ m/$keyid_regex/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 3 | $self->{handle} = $1; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 16 | ▶ | if (none { $type eq $_ } qw(userid keyid keyfile keystore)) { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 0 | croak "unknown type parameter value $type"; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 16 | return; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | sub needs_keystore { | ||||||||||||||||||
|
Subroutine
needs_keystore: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | return any { $self->{type} eq $_ } qw(keyid userid); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | ▶ | sub set { | ||||||||||||||||||
|
Subroutine
set: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 95 | 0 | my ($self, $type, $handle) = @_; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | $self->{type} = $type; | |||||||||||||||||||
| 98 | 0 | $self->{handle} = $handle; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | $self->_sanitize(); | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 20 | ▶ | sub type { | ||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 104 | 20 | my $self = shift; | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 20 | return $self->{type}; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 20 | ▶ | sub handle { | ||||||||||||||||||
|
Subroutine
handle: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 110 | 20 | my $self = shift; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 20 | return $self->{handle}; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head1 CHANGES | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =head2 Version 0.xx | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | This is a private module. | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 6 | 1; | |||||||||||||||||||