PGP-Finger

 view release on metacpan or  search on metacpan

lib/PGP/Finger/Key.pm  view on Meta::CPAN

package PGP::Finger::Key;

use Moose;

# ABSTRACT: class for holding and parsing pgp keys
our $VERSION = '1.1'; # VERSION

use Digest::SHA qw(sha256_hex sha224_hex);
use Digest::CRC qw(crcopenpgparmor_base64);
use MIME::Base64;

use overload
    q{""}    => sub { $_[0]->armored },
    fallback => 1;


has 'data' => ( is => 'ro' );

has 'attributes' => ( is => 'ro', isa => 'HashRef[Str]', lazy => 1,
	traits => [ 'Hash' ],
	default => sub { {} },
	handles => {
		set_attr => 'set',
		get_attr => 'get',
		has_attr => 'exists',
		has_attrs => 'count',
	},
);

has '_version' => ( is => 'ro', isa => 'Str', lazy => 1,
	default => sub {
		my $version;
		{
			no strict 'vars'; # is only declared in build
			$version = defined $VERSION ? $VERSION : 'head';
		}
		return 'pgpfinger ('.$version.')';
	},
);

sub merge_key {
	my ( $self, @keys ) = @_;

	foreach my $key ( @keys ) {
		$self->merge_attributes( $key->attributes );
	}
	return;
}

sub merge_attributes {
	my ( $self, $attr ) = @_;

	foreach my $name ( keys %$attr ) {
		if( ! $self->has_attr( $name ) ) {
			$self->set_attr( $name => $attr->{$name} );
		} else {
			$self->set_attr( $name => $self->get_attr($name).', '.$attr->{$name} );
		}
	}
	return;
}

sub new_armored {
	my ( $class, %options ) = @_;
	my $armored = $options{'data'};
	if( ! defined $armored ) {
		die('new_armored called without data');
	}
	
	my $b64 = '';
	my @lines = split( /\r?\n/, $armored );
	my $line;
	while( $line = shift @lines ) {
		if( $line =~ /^\s*$/ ) { next; }
		if( $line =~ /^-----BEGIN /) { last; } # here we start
		die('data before BEGIN line in PEM input');
	}
	if( ! @lines ) {
		die('end of PEM before -----BEGIN line has been found');



( run in 1.347 second using v1.01-cache-2.11-cpan-39bf76dae61 )