aboutsummaryrefslogtreecommitdiffstats
path: root/URPM/Signature.pm
diff options
context:
space:
mode:
authorFrancois Pons <fpons@mandriva.com>2003-08-06 09:50:55 +0000
committerFrancois Pons <fpons@mandriva.com>2003-08-06 09:50:55 +0000
commit2ea92271fbe8935f6ef2e83f25ec824cd9d50c20 (patch)
tree55714ac7d6fb639a16118356bf7298aeccbe8ab5 /URPM/Signature.pm
parentb26fea9e305277b2874e2c7118be8da1bcc4a2a9 (diff)
downloadperl-URPM-2ea92271fbe8935f6ef2e83f25ec824cd9d50c20.tar
perl-URPM-2ea92271fbe8935f6ef2e83f25ec824cd9d50c20.tar.gz
perl-URPM-2ea92271fbe8935f6ef2e83f25ec824cd9d50c20.tar.bz2
perl-URPM-2ea92271fbe8935f6ef2e83f25ec824cd9d50c20.tar.xz
perl-URPM-2ea92271fbe8935f6ef2e83f25ec824cd9d50c20.zip
initial support for parsing armored file (without gpg) and registering rpmdb pubkeys.
Diffstat (limited to 'URPM/Signature.pm')
-rw-r--r--URPM/Signature.pm77
1 files changed, 77 insertions, 0 deletions
diff --git a/URPM/Signature.pm b/URPM/Signature.pm
new file mode 100644
index 0000000..4e7ef70
--- /dev/null
+++ b/URPM/Signature.pm
@@ -0,0 +1,77 @@
+package URPM;
+
+use strict;
+
+#- parse an armored file and import in keys hash if the key does not already exists.
+sub parse_armored_file {
+ my ($urpm, $file) = @_;
+ my ($block, @l, $contents);
+ 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, $contents;
+ $block = undef;
+ $contents = '';
+ } else {
+ $contents .= $_;
+ }
+ }
+ }
+ }
+ close F or die "unable to parse armored file $file";
+
+ #- check only one key has been found.
+ @l > 1 and die "armored file contains more than one key";
+ @l < 1 and die "no key found while parsing armored file";
+
+ #- check if key has been found, remove from list.
+ @l = grep {
+ my $found = 0;
+ foreach my $k (values %{$urpm->{keys}}) {
+ $k->{contents} eq $_ and $found = 1, last;
+ }
+ !$found;
+ } @l;
+
+ #- now return something (true) which reflect what should be found in keys.
+ map { +{ contents => $_ } } @l;
+}
+
+#- pare from rpmdb.
+sub parse_rpmdb_pubkeys {
+ my ($urpm, $db) = @_;
+ my ($block, @l, $contents);
+
+ $db->traverse_tag('name', [ 'gpg-pubkey' ], sub {
+ my ($p) = @_;
+ my $s;
+ foreach (split "\n", $p->description) {
+ $block ||= /^-----BEGIN PGP PUBLIC KEY BLOCK-----$/;
+ if ($block) {
+ my $inside_block = /^$/ ... /^-----END PGP PUBLIC KEY BLOCK-----$/;
+ if ($inside_block > 1) {
+ if ($inside_block =~ /E/) {
+ $urpm->{keys}{$p->version} = { $p->summary =~ /^gpg\(\)$/ ? (name => $1) : @{[]},
+ id => $p->version,
+ contents => $contents,
+ };
+ $block = undef;
+ $contents = '';
+ } else {
+ $contents .= $_;
+ }
+ }
+ }
+ }
+ })
+}
+
+1;