]> git.proxmox.com Git - pve-common.git/commitdiff
cert: check_pem: code reduction/cleanup
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 7 Mar 2023 17:21:05 +0000 (18:21 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 7 Mar 2023 17:36:44 +0000 (18:36 +0100)
mainly by avoiding the useless intermediate variables

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/Certificate.pm

index 03f27fc1e20556c2b80a8329acdf577cdfcdcd9b..7fabc3ad7438a7b329f60ed65b7063d2cc272fe5 100644 (file)
@@ -134,22 +134,15 @@ sub split_pem {
 sub check_pem {
     my ($content, %opts) = @_;
 
-    my $label = $opts{label} // 'CERTIFICATE';
-    my $multiple = $opts{multiple};
-    my $noerr = $opts{noerr};
-
     $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 $content;
-    } else {
-       return undef if $noerr;
-       die "not a valid PEM-formatted string.\n";
-    }
+    return undef if $opts{noerr};
+    die "not a valid PEM-formatted string.\n";
 }
 
 sub pem_to_der {