Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/Crypt/OpenPGP/KeyRing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ sub restore {
my($buf) = @_;
$ring->{blocks} = [];
my($kb);
while (my $packet = Crypt::OpenPGP::PacketFactory->parse($buf)) {
if (ref($packet) eq "Crypt::OpenPGP::Certificate" &&
!$packet->is_subkey) {
$kb = Crypt::OpenPGP::KeyBlock->new;
$ring->add($kb);
do {
my $packet = Crypt::OpenPGP::PacketFactory->parse($buf);
if (defined $packet) {
if (ref($packet) eq "Crypt::OpenPGP::Certificate" &&
!$packet->is_subkey) {
$kb = Crypt::OpenPGP::KeyBlock->new;
$ring->add($kb);
}
$kb->add($packet) if $kb;
} else {
warn("Failed to parse packet: " .
Crypt::OpenPGP::PacketFactory->errstr);
}
$kb->add($packet) if $kb;
}
} while($buf->offset < $buf->length);
}

sub add {
Expand Down
4 changes: 4 additions & 0 deletions lib/Crypt/OpenPGP/PacketFactory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ sub parse {
eval "use $pkt_class;";
return $class->error("Loading $pkt_class failed: $@") if $@;
$obj = $pkt_class->parse($b, @args);
if (!defined $obj) {
return $class->error("Parsing packet of type $pkt_class failed: " .
$pkt_class->errstr);
}
}
else {
$obj = { type => $type, length => $len,
Expand Down