5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2025-01-23 10:03:33 +03:00

cert: check_pem: code reduction/cleanup

mainly by avoiding the useless intermediate variables

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2023-03-07 18:21:05 +01:00
parent 060a437fe9
commit 6baa9131aa

View File

@ -134,22 +134,15 @@ sub split_pem {
sub check_pem { sub check_pem {
my ($content, %opts) = @_; my ($content, %opts) = @_;
my $label = $opts{label} // 'CERTIFICATE';
my $multiple = $opts{multiple};
my $noerr = $opts{noerr};
$content = strip_leading_text($content); $content = strip_leading_text($content);
my $re = $pem_re->($label); my $re = $pem_re->($opts{label} // 'CERTIFICATE');
$re = qr/($re\n+)*$re/ if $opts{multiple};
$re = qr/($re\n+)*$re/ if $multiple; return $content if $content =~ /^$re$/; # OK
if ($content =~ /^$re$/) { return undef if $opts{noerr};
return $content; die "not a valid PEM-formatted string.\n";
} else {
return undef if $noerr;
die "not a valid PEM-formatted string.\n";
}
} }
sub pem_to_der { sub pem_to_der {