move it to function

This commit is contained in:
Florian Obser 2017-04-23 09:25:17 +02:00
parent 7d4715c9f5
commit 6ea7b77093

View File

@ -18,11 +18,16 @@ sub usage {
usage() if (scalar(@ARGV) != 2); usage() if (scalar(@ARGV) != 2);
gen_tlsa(@ARGV);
sub gen_tlsa {
my ($label, $cert_file) = @_;
my $state = WAIT_BEGIN; my $state = WAIT_BEGIN;
my $pem = ''; my $pem = '';
my ($fh, $line);
open(my $fh, '<', $ARGV[1]); open($fh, '<', $cert_file);
while(my $line = <$fh>) { while($line = <$fh>) {
if ($state == WAIT_BEGIN) { if ($state == WAIT_BEGIN) {
if ($line=~/^-----BEGIN CERTIFICATE-----/) { if ($line=~/^-----BEGIN CERTIFICATE-----/) {
$state = WAIT_END; $state = WAIT_END;
@ -36,6 +41,6 @@ while(my $line = <$fh>) {
} }
} }
close($fh); close($fh);
say $ARGV[0], ' IN TLSA 1 0 1 ', Digest::SHA::sha256_hex(decode_base64($pem)); say($label, ' IN TLSA 1 0 1 ',
Digest::SHA::sha256_hex(decode_base64($pem)));
#say $pem; }