aboutsummaryrefslogtreecommitdiffstats
path: root/URPM
diff options
context:
space:
mode:
authorFrancois Pons <fpons@mandriva.com>2003-08-21 13:04:42 +0000
committerFrancois Pons <fpons@mandriva.com>2003-08-21 13:04:42 +0000
commit8a2907b8af95bd0bac5abc71b5c5707250271059 (patch)
tree33282a5fc315dde2530ef4226b2cba9bf97e788c /URPM
parentdeb40023171c3f2d5bc2cf6bdd33dedb087c2831 (diff)
downloadperl-URPM-8a2907b8af95bd0bac5abc71b5c5707250271059.tar
perl-URPM-8a2907b8af95bd0bac5abc71b5c5707250271059.tar.gz
perl-URPM-8a2907b8af95bd0bac5abc71b5c5707250271059.tar.bz2
perl-URPM-8a2907b8af95bd0bac5abc71b5c5707250271059.tar.xz
perl-URPM-8a2907b8af95bd0bac5abc71b5c5707250271059.zip
0.94-1mdk (URPM::Signature fixes and changes)0.94
Diffstat (limited to 'URPM')
-rw-r--r--URPM/Signature.pm115
1 files changed, 59 insertions, 56 deletions
diff --git a/URPM/Signature.pm b/URPM/Signature.pm
index 5ef9bbe..78fdbd5 100644
--- a/URPM/Signature.pm
+++ b/URPM/Signature.pm
@@ -25,6 +25,41 @@ sub compare_pubkeys {
$diff <= $options{diff} ? 0 : $diff;
}
+#- parse an armored file and import in keys hash if the key does not already exists.
+sub parse_armored_file {
+ my ($urpm, $file, %options) = @_;
+ my ($block, $content, @l);
+
+ #- check if an already opened file has been given directly.
+ unless (ref $file) {
+ my $F;
+ open $F, $file;
+ $file = $F;
+ }
+
+ #- read armored file.
+ local $_;
+ while (<$file>) {
+ my $inside_block = /^-----BEGIN PGP PUBLIC KEY BLOCK-----$/ ... /^-----END PGP PUBLIC KEY BLOCK-----$/;
+ if ($inside_block) {
+ $block .= $_;
+ if ($inside_block =~ /E/) {
+ #- block is needed to import the key if needed.
+ push @l, { block => $block, content => $content };
+ $block = $content = undef;
+ } else {
+ #- compute content for finding the right key.
+ chomp;
+ /^$/ and $content = '';
+ defined $content and $content .= $_;
+ }
+ }
+ }
+ close F;
+
+ @l;
+}
+
#- pare from rpmlib db.
sub parse_pubkeys {
my ($urpm, %options) = @_;
@@ -45,6 +80,7 @@ sub parse_pubkeys {
$urpm->{keys}{$p->version} = { $p->summary =~ /^gpg\((.*)\)$/ ? (name => $1) : @{[]},
id => $p->version,
content => $content,
+ block => $p->description,
};
$block = undef;
$content = '';
@@ -57,68 +93,35 @@ sub parse_pubkeys {
})
}
-#- parse an armored file and import in keys hash if the key does not already exists.
-sub parse_armored_file {
- my ($urpm, $file, %options) = @_;
- my ($block, @l, $content);
- local (*F, $_);
-
- #- read armored file.
- open F, $file;
- while (<F>) {
- chomp;
- $block ||= /^-----BEGIN PGP PUBLIC KEY BLOCK-----$/;
- if ($block) {
- my $inside_block = /^$/ ... /^-----END PGP PUBLIC KEY BLOCK-----$/;
- if ($inside_block > 1) {
- if ($inside_block =~ /E/) {
- push @l, +{ content => $content };
- $block = undef;
- $content = '';
- } else {
- $content .= $_;
- }
- }
- }
- }
- close F or die "unable to parse armored file $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} || {}}) {
- compare_pubkeys($k, $_) == 0 and $found = 1, last;
- }
- !$found;
- } @l;
- }
-
- @l;
-}
-
-sub import_armored_file {
- my ($urpm, $file, %options) = @_;
+#- import pubkeys only if it is needed.
+sub import_needed_pubkeys {
+ my ($urpm, $l, %options) = @_;
local (*F, $_);
my $block = '';
- #- read armored file.
- open F, $file;
- while (<F>) {
- my $inside_block = /^-----BEGIN PGP PUBLIC KEY BLOCK-----$/ ... /^-----END PGP PUBLIC KEY BLOCK-----$/;
- if ($inside_block) {
- $block .= $_;
- if ($inside_block =~ /E/) {
- #- import key using the given database if any else the function will open the rpmdb itself.
- #- FIXME workaround for rpm 4.2 if the rpmdb is left opened, the keys content are sligtly
- #- modified by algorithms...
- URPM::import_pubkey(block => $block, db => $options{db}, root => $options{root})
- or die "import of armored file failed";
- $block = '';
+ #- use the same database handle to avoid re-opening multiple times the database.
+ my $db = $options{db};
+ $db ||= URPM::DB::open($options{root}, 1);
+
+ #- assume $l is a reference to an array containing all the keys to import
+ #- if needed.
+ foreach my $k (@{$l || []}) {
+ my ($id, $imported);
+ foreach my $kv (values %{$urpm->{keys} || {}}) {
+ compare_pubkeys($k, $kv, %options) == 0 and $id = $kv->{id}, last;
+ }
+ unless ($id) {
+ $imported = 1;
+ import_pubkey(block => $k->{block}, db => $db);
+ $urpm->parse_pubkeys(db => $db);
+ foreach my $kv (values %{$urpm->{keys} || {}}) {
+ compare_pubkeys($k, $kv, %options) == 0 and $id = $kv->{id}, last;
}
}
+ #- let the caller know about what has been found.
+ #- this is an error if the key is not found.
+ $options{callback} and $options{callback}->($urpm, $db, $k, $id, $imported, %options);
}
- close F or die "unable to parse armored file $file";
}
1;