From 94f54d725c6da7a6f91bf4701b4a5af28d0dd2fd Mon Sep 17 00:00:00 2001 From: Francois Pons Date: Wed, 20 Aug 2003 15:10:25 +0000 Subject: 0.93-7mdk (signature comparison workaround) --- URPM/Signature.pm | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'URPM') diff --git a/URPM/Signature.pm b/URPM/Signature.pm index e2089e6..b3ca91b 100644 --- a/URPM/Signature.pm +++ b/URPM/Signature.pm @@ -2,6 +2,29 @@ package URPM; use strict; +#- compare keys to avoid glitches introduced during the importation where +#- some characters may be modified on the fly by rpm --import... +sub compare_pubkeys { + my ($a, $b, %options) = @_; + my $diff = 0; + my @a = unpack "C*", $a->{content}; + my @b = unpack "C*", $b->{content}; + + #- default options to use. + $options{start} ||= 0; + $options{end} ||= @a < @b ? scalar(@b) : scalar(@a); + $options{diff} ||= 1; + + #- check element one by one, count all difference (do not work well if elements + #- have been inserted/deleted). + foreach ($options{start} .. $options{end}) { + $a[$_] != $b[$_] and ++$diff; + } + + #- diff options give level to consider the key equal (a character is not always the same). + $diff <= $options{diff} ? 0 : $diff; +} + #- pare from rpmlib db. sub parse_pubkeys { my ($urpm, %options) = @_; @@ -49,7 +72,7 @@ sub parse_armored_file { my $inside_block = /^$/ ... /^-----END PGP PUBLIC KEY BLOCK-----$/; if ($inside_block > 1) { if ($inside_block =~ /E/) { - push @l, $content; + push @l, +{ content => $content }; $block = undef; $content = ''; } else { @@ -60,22 +83,18 @@ sub parse_armored_file { } close F or die "unable to parse armored file $file"; - #- check at least one key has been found. - @l < 1 and die "no key found while parsing armored file"; - #- check if key has been found, remove from list. if ($options{only_unknown_keys}) { @l = grep { my $found = 0; foreach my $k (values %{$urpm->{keys} || {}}) { - $k->{content} eq $_ and $found = 1, last; + compare_pubkeys($k, $_) == 0 and $found = 1, last; } !$found; } @l; } - #- now return something (true) which reflect what should be found in keys. - map { +{ content => $_ } } @l; + @l; } sub import_armored_file { -- cgit v1.2.1