[pve-devel] [PATCH v4 common 2/7] tools: add download_file_from_url

Thomas Lamprecht t.lamprecht at proxmox.com
Thu May 6 14:17:32 CEST 2021


On 06.05.21 14:15, Thomas Lamprecht wrote:
> sub check_file_hash
>    my ($algorithm, $expected, $file) = @_;
> 
>    my $algorithm_map = {
>       'sha256' => sub { Digest::SHA->new(512) },

argh, naturally above should use 256, but you get the idea ;-)

>       'sha512' => sub { Digest::SHA->new(512) },
>       # etc...
>    };
> 
>    my $digester = $algorithm_map->{$algorithm}->() or die "unknown algorithm '$algorithm'\n";
> 
>    open(my $fh, '<', $filename) or die "cannot open file '$file': $!\n";
> 
>    my $got = $digester->addfile($fh)->hexdigest;
>    close($fh);
> 
>    return lc($digest) eq lc($expected);
> }





More information about the pve-devel mailing list