[Pkg-privacy-commits] [msva-perl] 326/356: added Crypt::Monkeysphere::Validator->findall()
Ximin Luo
infinity0 at moszumanska.debian.org
Mon Aug 24 07:42:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository msva-perl.
commit b60db331eff0d40904d6684dd6124280f4b68e7f
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date: Thu Apr 21 22:54:19 2011 -0400
added Crypt::Monkeysphere::Validator->findall()
---
Crypt/Monkeysphere/Validator.pm | 61 ++++++++++++++++++++++++++++++++++++
unit-tests/20.validator/10.findall.t | 41 ++++++++++++++++++++++++
2 files changed, 102 insertions(+)
diff --git a/Crypt/Monkeysphere/Validator.pm b/Crypt/Monkeysphere/Validator.pm
index 66fc638..3247f0c 100644
--- a/Crypt/Monkeysphere/Validator.pm
+++ b/Crypt/Monkeysphere/Validator.pm
@@ -147,6 +147,67 @@ sub lookup {
return $self->_tryquery(uid => $opts{uid}, fpr => $opts{fpr}, key => $opts{key});
}
+sub valid_binding {
+ my $self = shift;
+ my $uid = shift;
+ my $gpgkey = shift;
+
+ my $validity = '-';
+ foreach my $tryuid ($gpgkey->user_ids) {
+ if ($tryuid->as_string eq $uid) {
+ return 1
+ if $tryuid->validity =~ /^[fu]$/;
+ }
+ }
+ return 0;
+}
+
+=pod
+
+=head2 findall
+
+Find all keys with appropriate capabilities and valid bindings to the given uid.
+
+=cut
+
+sub findall{
+ my $self=shift;
+ my $uid=shift;
+
+ $self->fetch_uid($uid) if ($self->{kspolicy} eq 'always');
+
+ my @keys = $self->_findall($uid);
+
+ if (scalar(@keys) == 0 and $self->{kspolicy} eq 'unlessvalid'){
+ $self->fetch_uid($uid);
+ @keys=$self->_findall($uid);
+ }
+
+ return @keys;
+}
+
+sub _findall {
+ my $self=shift;
+ my $uid=shift;
+
+ my @keys;
+ my $x = 0;
+
+ foreach my $gpgkey ($self->{gnupg}->get_public_keys('='.$uid)) {
+ if ($self->valid_binding($uid, $gpgkey)) {
+ foreach my $subkey ($gpgkey, @{$gpgkey->subkeys()}) {
+ if ($self->test_capable($subkey) ) {
+ $self->log('verbose', "key 0x%s is capable...\n",$subkey->hex_id);
+
+ push(@keys, $subkey);
+ }
+ }
+ }
+ }
+ return @keys;
+}
+
+
sub keycomp {
my $self=shift;
my $rsakey = shift;
diff --git a/unit-tests/20.validator/10.findall.t b/unit-tests/20.validator/10.findall.t
new file mode 100644
index 0000000..fc316d5
--- /dev/null
+++ b/unit-tests/20.validator/10.findall.t
@@ -0,0 +1,41 @@
+# -*- perl -*-
+use Test::More;
+
+use Crypt::Monkeysphere::Validator;
+use GnuPG::Interface;
+use File::Temp qw(tempdir);
+use Data::Dumper;
+
+use strict;
+
+
+my $gpgdir = $ENV{MSTEST_GNUPGHOME};
+
+unless (defined $gpgdir && -d $gpgdir){
+ plan skip_all => "Preseeded GPGHOME not found";
+ goto end;
+}
+
+
+my $gnupg = new GnuPG::Interface();
+$gnupg->options->hash_init(homedir=>$gpgdir);
+
+my $validator=new Crypt::Monkeysphere::Validator(gnupg=>$gnupg,
+ kspolicy=>'never',
+ loglevel=>'debug');
+
+
+plan tests =>2;
+
+isa_ok($validator,'Crypt::Monkeysphere::Validator');
+
+my $uid='Joe Tester <joe at example.net>';
+
+my @keys=$validator->findall($uid);
+
+
+
+ok(scalar @keys >= 3);
+
+
+end:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/msva-perl.git
More information about the Pkg-privacy-commits
mailing list