[Bps-public-commit] GnuPG-Interface branch, master, updated. 0.42_01-5-ge33e2d5

Jesse Vincent jesse at bestpractical.com
Sat Jun 5 18:51:27 EDT 2010


The branch, master has been updated
       via  e33e2d54b56ac968ea76fb120b92ec305eeea1ec (commit)
       via  de8aed494beff53d19e23022bc7bb953159af487 (commit)
       via  80acbe62630e16ede47f6725dad1be6e6da2b1fc (commit)
       via  1a5fdc7263184c18ee7a341f451b1fa945986ff9 (commit)
       via  89deaf167d754ad79c4be01dda06e46dd82d080f (commit)
      from  3b5e1b390bbbb9e67003b0a9a11bbfb416a1911e (commit)

Summary of changes:
 MANIFEST                        |    6 --
 lib/GnuPG/Interface.pm          |    6 ++
 lib/GnuPG/Key.pm                |  100 ++++++++++++++++++++++++++++++++-----
 lib/GnuPG/PrimaryKey.pm         |   38 ++++++++++++++-
 lib/GnuPG/Revoker.pm            |    3 +-
 lib/GnuPG/UserId.pm             |   34 +++++++++++++
 t/GnuPG/ComparableKey.pm        |   73 ---------------------------
 t/GnuPG/ComparablePrimaryKey.pm |   52 -------------------
 t/GnuPG/ComparablePublicKey.pm  |   22 --------
 t/GnuPG/ComparableSecretKey.pm  |   22 --------
 t/GnuPG/ComparableSubKey.pm     |   51 -------------------
 t/GnuPG/ComparableUserId.pm     |   63 -----------------------
 t/get_public_keys.t             |  104 ++++++++++++++++++++++++++++++++++++---
 t/get_secret_keys.t             |   17 ++++--
 14 files changed, 271 insertions(+), 320 deletions(-)
 delete mode 100644 t/GnuPG/ComparableKey.pm
 delete mode 100644 t/GnuPG/ComparablePrimaryKey.pm
 delete mode 100644 t/GnuPG/ComparablePublicKey.pm
 delete mode 100644 t/GnuPG/ComparableSecretKey.pm
 delete mode 100644 t/GnuPG/ComparableSubKey.pm
 delete mode 100644 t/GnuPG/ComparableUserId.pm

- Log -----------------------------------------------------------------
commit 89deaf167d754ad79c4be01dda06e46dd82d080f
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Tue May 11 14:02:49 2010 -0400

    moved compare() into GnuPG::UserID, got rid of testing-only ComparableUserID

diff --git a/MANIFEST b/MANIFEST
index 4cfbbb8..bea9c6f 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -43,7 +43,6 @@ t/GnuPG/ComparablePrimaryKey.pm
 t/GnuPG/ComparablePublicKey.pm
 t/GnuPG/ComparableSecretKey.pm
 t/GnuPG/ComparableSubKey.pm
-t/GnuPG/ComparableUserId.pm
 t/import_keys.t
 t/Interface.t
 t/list_public_keys.t
diff --git a/lib/GnuPG/UserId.pm b/lib/GnuPG/UserId.pm
index d75b273..eef2da1 100644
--- a/lib/GnuPG/UserId.pm
+++ b/lib/GnuPG/UserId.pm
@@ -41,6 +41,34 @@ sub push_revocations {
     push @{ $self->revocations }, @_;
 }
 
+sub compare {
+  my ( $self, $other, $deep ) = @_;
+
+  my @comparison_ints = qw( validity as_string );
+
+  foreach my $field ( @comparison_ints ) {
+    return 0 unless $self->$field() eq $other->$field();
+  }
+
+  return 0 unless @{$self->signatures} == @{$other->signatures};
+  return 0 unless @{$self->revocations} == @{$other->revocations};
+
+  # FIXME: is it actually wrong if the associated signatures come out
+  # in a different order on the two compared designated revokers?
+  if (defined $deep && $deep) {
+    for ( my $i = 0; $i < scalar(@{$self->signatures}); $i++ ) {
+      return 0
+        unless $self->signatures->[$i]->compare($other->signatures->[$i], 1);
+    }
+    for ( my $i = 0; $i < scalar(@{$self->revocations}); $i++ ) {
+      return 0
+        unless $self->revocations->[$i]->compare($other->revocations->[$i], 1);
+    }
+  }
+
+  return 1;
+}
+
 
 # DEPRECATED
 sub user_id_string {
@@ -79,6 +107,12 @@ objects.
 This methods creates a new object.  The optional arguments are
 initialization of data members;
 
+=item compare( I<$other>, I<$deep> )
+
+Returns non-zero only when this User ID is identical to the other
+GnuPG::UserID.  If $deep is present and non-zero, the User ID's
+signatures and revocations will also be compared.
+
 =back
 
 =head1 OBJECT DATA MEMBERS
diff --git a/t/GnuPG/ComparableUserId.pm b/t/GnuPG/ComparableUserId.pm
deleted file mode 100644
index ff9fb02..0000000
--- a/t/GnuPG/ComparableUserId.pm
+++ /dev/null
@@ -1,63 +0,0 @@
-#  ComparableUserId.pm
-#    - providing an object-oriented approach to GnuPG user ids
-#
-#  Copyright (C) 2000 Frank J. Tobin <ftobin at cpan.org>
-#
-#  This module is free software; you can redistribute it and/or modify it
-#  under the same terms as Perl itself.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-#
-#  $Id: ComparableUserId.pm,v 1.3 2001/09/14 12:34:36 ftobin Exp $
-#
-
-package GnuPG::ComparableUserId;
-
-use strict;
-
-use base qw( GnuPG::UserId );
-
-sub compare
-{
-    my ( $self, $other, $deep ) = @_;
-    
-    return 0 unless $self->user_id_string() eq $other->user_id_string();
-    return 0 unless $self->_deeply_compare( $other );
-    return 1;
-}
-
-
-sub _deeply_compare
-{
-    my ( $self, $other ) = @_;
-    
-    return 0 unless
-      $self->rigorously_compare( $other );
-
-    my @self_signatures  = $self->signatures();
-    my @other_signatures = $other->signatures();
-    
-    return 0 unless @self_signatures == @other_signatures;
-    
-    my $num_sigs = @self_signatures;
-    my $i;
-    
-    for ( $i = 0; $i < $num_sigs; $i++ )
-    {
-	return 0
-	  unless $self_signatures[$i]->compare( $other_signatures[$i], 1 );
-    }
-
-    # FIXME: what if the other item has revocations that we don't have?
-    for ( $i = 0; $i < scalar(@{$self->revocations}); $i++ ) {
-      return 0
-        unless $self->revocations()->[$i]->compare($other->revocations()->[$i], 1);
-    }
-
-    return 1;
-}
-
-
-1;

commit 1a5fdc7263184c18ee7a341f451b1fa945986ff9
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Tue May 11 14:09:19 2010 -0400

    removed empty test-only ComparablePublicKey and ComparableSecretKey

diff --git a/MANIFEST b/MANIFEST
index bea9c6f..75bdfbc 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -40,8 +40,6 @@ t/get_public_keys.t
 t/get_secret_keys.t
 t/GnuPG/ComparableKey.pm
 t/GnuPG/ComparablePrimaryKey.pm
-t/GnuPG/ComparablePublicKey.pm
-t/GnuPG/ComparableSecretKey.pm
 t/GnuPG/ComparableSubKey.pm
 t/import_keys.t
 t/Interface.t
diff --git a/t/GnuPG/ComparablePublicKey.pm b/t/GnuPG/ComparablePublicKey.pm
deleted file mode 100644
index 2137850..0000000
--- a/t/GnuPG/ComparablePublicKey.pm
+++ /dev/null
@@ -1,22 +0,0 @@
-#  ComparablePublicKey.pm
-#      - Comparable GnuPG::PublicKeys
-#
-#  Copyright (C) 2000 Frank J. Tobin <ftobin at cpan.org>
-#
-#  This module is free software; you can redistribute it and/or modify it
-#  under the same terms as Perl itself.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-#
-#  $Id: ComparablePublicKey.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $
-#
-
-package GnuPG::ComparablePublicKey;
-
-use strict;
-
-use base qw( GnuPG::PublicKey GnuPG::ComparablePrimaryKey );
-
-1;
diff --git a/t/GnuPG/ComparableSecretKey.pm b/t/GnuPG/ComparableSecretKey.pm
deleted file mode 100644
index 3f3858f..0000000
--- a/t/GnuPG/ComparableSecretKey.pm
+++ /dev/null
@@ -1,22 +0,0 @@
-#  ComparableSecretKey.pm
-#    - Comparable GnuPG::SecretKey
-#
-#  Copyright (C) 2000 Frank J. Tobin <ftobin at cpan.org>
-#
-#  This module is free software; you can redistribute it and/or modify it
-#  under the same terms as Perl itself.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-#
-#  $Id: ComparableSecretKey.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $
-#
-
-package GnuPG::ComparableSecretKey;
-
-use strict;
-
-use base qw( GnuPG::SecretKey GnuPG::ComparablePrimaryKey );
-
-1;
diff --git a/t/get_public_keys.t b/t/get_public_keys.t
index 3dffe8c..61c475f 100644
--- a/t/get_public_keys.t
+++ b/t/get_public_keys.t
@@ -10,7 +10,7 @@ use lib './t';
 use MyTest;
 use MyTestSpecific;
 
-use GnuPG::ComparablePublicKey;
+use GnuPG::ComparablePrimaryKey;
 use GnuPG::ComparableSubKey;
 
 my ( $given_key, $handmade_key );
@@ -25,7 +25,7 @@ TEST
     
     $given_key = shift @returned_keys;
     
-    $handmade_key = GnuPG::ComparablePublicKey->new
+    $handmade_key = GnuPG::ComparablePrimaryKey->new
       ( length                 => 1024,
 	algo_num               => 17,
 	hex_id                 => '53AE596EF950DA9C',
diff --git a/t/get_secret_keys.t b/t/get_secret_keys.t
index 63c0400..342a68d 100644
--- a/t/get_secret_keys.t
+++ b/t/get_secret_keys.t
@@ -10,7 +10,7 @@ use lib './t';
 use MyTest;
 use MyTestSpecific;
 
-use GnuPG::ComparableSecretKey;
+use GnuPG::ComparablePrimaryKey;
 
 my ( $given_key, $handmade_key );
 
@@ -24,7 +24,7 @@ TEST
     
     $given_key = shift @returned_keys;
     
-    $handmade_key = GnuPG::ComparableSecretKey->new
+    $handmade_key = GnuPG::ComparablePrimaryKey->new
       ( length                 => 1024,
 	algo_num               => 17,
 	hex_id                 => '53AE596EF950DA9C',

commit 80acbe62630e16ede47f6725dad1be6e6da2b1fc
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Tue May 11 20:28:54 2010 -0400

    only compare number of signatures in GnuPG::Revoker if $deep is non-zero

diff --git a/lib/GnuPG/Revoker.pm b/lib/GnuPG/Revoker.pm
index e5adc31..151a2f5 100644
--- a/lib/GnuPG/Revoker.pm
+++ b/lib/GnuPG/Revoker.pm
@@ -57,11 +57,10 @@ sub compare {
 
   return 0 unless $self->fingerprint->compare($other->fingerprint);
 
-  return 0 unless @{$self->signatures} == @{$other->signatures};
-
   # FIXME: is it actually wrong if the associated signatures come out
   # in a different order on the two compared designated revokers?
   if (defined $deep && $deep) {
+    return 0 unless @{$self->signatures} == @{$other->signatures};
     for ( my $i = 0; $i < scalar(@{$self->signatures}); $i++ ) {
       return 0
         unless $self->signatures->[$i]->compare($other->signatures->[$i], 1);

commit de8aed494beff53d19e23022bc7bb953159af487
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Tue May 11 22:06:52 2010 -0400

    moved all comparison functionality into main GnuPG objects (no longer testing-only)

diff --git a/MANIFEST b/MANIFEST
index 75bdfbc..14a2164 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -38,9 +38,6 @@ t/export_keys.t
 t/Fingerprint.t
 t/get_public_keys.t
 t/get_secret_keys.t
-t/GnuPG/ComparableKey.pm
-t/GnuPG/ComparablePrimaryKey.pm
-t/GnuPG/ComparableSubKey.pm
 t/import_keys.t
 t/Interface.t
 t/list_public_keys.t
diff --git a/lib/GnuPG/Key.pm b/lib/GnuPG/Key.pm
index cfe9fb8..1500d4b 100644
--- a/lib/GnuPG/Key.pm
+++ b/lib/GnuPG/Key.pm
@@ -34,7 +34,12 @@ has [
     is  => 'rw',
     );
 
-has signatures => (
+has [
+     qw(
+         signatures
+         revokers
+         revocations
+      )] => (
     isa       => 'ArrayRef',
     is        => 'rw',
     default   => sub { [] },
@@ -45,23 +50,11 @@ sub push_signatures {
     push @{ $self->signatures }, @_;
 }
 
-has revocations => (
-    isa       => 'ArrayRef',
-    is        => 'rw',
-    default   => sub { [] },
-);
-
 sub push_revocations {
     my $self = shift;
     push @{ $self->revocations }, @_;
 }
 
-has revokers => (
-    isa       => 'ArrayRef',
-    is        => 'rw',
-    default   => sub { [] },
-);
-
 sub push_revokers {
     my $self = shift;
     push @{ $self->revokers }, @_;
@@ -72,6 +65,59 @@ sub short_hex_id {
     return substr $self->hex_id(), -8;
 }
 
+sub compare {
+  my ($self, $other, $deep) = @_;
+
+  my @string_comparisons = qw(
+    length
+    algo_num
+    hex_id
+    creation_date
+    creation_date_string
+    usage_flags
+                           );
+
+  my $field;
+  foreach $field (@string_comparisons) {
+    return 0 unless $self->$field eq $other->$field;
+  }
+
+  my @can_be_undef = qw(
+    hex_data
+    expiration_date
+    expiration_date_string
+  );
+  foreach $field (@can_be_undef) {
+    return 0 unless (defined $self->$field) == (defined $other->$field);
+    if (defined $self->$field) {
+      return 0 unless $self->$field eq $other->$field;
+    }
+  }
+  my @objs = qw(
+    fingerprint
+  );
+  foreach $field (@objs) {
+    return 0 unless $self->$field->compare($other->$field, $deep);
+  }
+
+  if (defined $deep && $deep) {
+    my @lists = qw(
+      signatures
+      revokers
+      revocations
+                 );
+
+    foreach my $list (@lists) {
+      return 0 unless @{$self->$list} == @{$other->$list};
+      for ( my $i = 0; $i < scalar(@{$self->$list}); $i++ ) {
+        return 0
+          unless $self->$list->[$i]->compare($other->$list->[$i], $deep);
+      }
+    }
+  }
+  return 1;
+}
+
 __PACKAGE__->meta->make_immutable;
 
 1;
@@ -114,6 +160,12 @@ initialization of data members.
 This returns the commonly-used short, 8 character short hex id
 of the key.
 
+=item compare( I<$other>, I<$deep> )
+
+Returns non-zero only when this Key is identical to the other
+GnuPG::Key.  If $deep is present and non-zero, the key's associated
+signatures, revocations, and revokers will also be compared.
+
 =back
 
 =head1 OBJECT DATA MEMBERS
diff --git a/lib/GnuPG/PrimaryKey.pm b/lib/GnuPG/PrimaryKey.pm
index 1c61d2c..d36d0b9 100644
--- a/lib/GnuPG/PrimaryKey.pm
+++ b/lib/GnuPG/PrimaryKey.pm
@@ -38,6 +38,40 @@ has $_ => (
     clearer => 'clear_' . $_,
 ) for qw( local_id owner_trust );
 
+
+sub compare {
+  my ($self, $other, $deep) = @_;
+
+  # not comparing local_id because it is meaningless in modern
+  # versions of GnuPG.
+  my @comparison_fields = qw (
+     owner_trust
+  );
+
+  foreach my $field (@comparison_fields) {
+    return 0 unless $self->$field eq $other->$field;
+  }
+
+  if (defined $deep && $deep) {
+    my @lists = qw(
+      user_ids
+      subkeys
+      user_attributes
+                 );
+
+    foreach my $list (@lists) {
+      return 0 unless @{$self->$list} == @{$other->$list};
+      for ( my $i = 0; $i < scalar(@{$self->$list}); $i++ ) {
+        return 0
+          unless $self->$list->[$i]->compare($other->$list->[$i], 1);
+      }
+    }
+  }
+
+  return $self->SUPER::compare($other, $deep);
+}
+
+
 __PACKAGE__->meta->make_immutable;
 
 1;
@@ -88,7 +122,9 @@ A list of GnuPG::SubKey objects associated with this key.
 
 =item local_id
 
-GnuPG's local id for the key.
+WARNING: DO NOT USE.  This used to mean GnuPG's local id for the key,
+but modern versions of GnuPG do not produce it.  Expect this to be the
+empty string or undef.
 
 =item owner_trust
 
diff --git a/t/GnuPG/ComparableKey.pm b/t/GnuPG/ComparableKey.pm
deleted file mode 100644
index 61f9d53..0000000
--- a/t/GnuPG/ComparableKey.pm
+++ /dev/null
@@ -1,73 +0,0 @@
-#  ComparableKey.pm
-#    - comparable GnuPG::Key
-#
-#  Copyright (C) 2000 Frank J. Tobin <ftobin at cpan.org>
-#
-#  This module is free software; you can redistribute it and/or modify it
-#  under the same terms as Perl itself.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-#
-#  $Id: ComparableKey.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $
-#
-
-package GnuPG::ComparableKey;
-
-use strict;
-use GnuPG::Fingerprint;
-
-use base qw( GnuPG::Key );
-
-sub compare
-{
-    my ( $self, $other, $deep ) = @_;
-    
-    # expiration_date_string and expiration_date was taken out of the
-    # following list because there is a bug in the listing of
-    # expiration dates in 1.0.5
-    my @comparison_fields
-      = qw( length algo_num hex_id creation_date
-	    creation_date_string usage_flags
-	  );
-    
-    foreach my $field ( @comparison_fields )
-    {
-	# don't test for definedness because
-	# all fields should be defined
-	return 0 unless $self->$field() eq $other->$field();
-    }
-    
-    return $self->_deeply_compare( $other ) if $deep;
-    
-    return 1;
-}
-
-
-sub _deeply_compare
-{
-    my ( $self, $other ) = @_;
-    my $i;
-
-    for ( $i = 0; $i < scalar(@{$self->signatures}); $i++ ) {
-      return 0
-        unless $self->signatures->[$i]->compare($other->signatures->[$i], 1);
-    }
-
-    for ( $i = 0; $i < scalar(@{$self->revocations}); $i++ ) {
-      return 0
-        unless $self->revocations->[$i]->compare($other->revocations->[$i], 1);
-    }
-
-    for ( $i = 0; $i < scalar(@{$self->revokers}); $i++ ) {
-      return 0
-        unless $self->revokers->[$i]->compare($other->revokers->[$i], 1);
-    }
-
-    bless $self->fingerprint(), 'GnuPG::Fingerprint';
-    return ( $self->fingerprint->compare( $other->fingerprint() ) );
-}
-
-
-1;
diff --git a/t/GnuPG/ComparablePrimaryKey.pm b/t/GnuPG/ComparablePrimaryKey.pm
deleted file mode 100644
index 24f7d1f..0000000
--- a/t/GnuPG/ComparablePrimaryKey.pm
+++ /dev/null
@@ -1,52 +0,0 @@
-#  ComparablePrimaryKey.pm
-#      - Comparable GnuPG::PrimaryKey
-#
-#  Copyright (C) 2000 Frank J. Tobin <ftobin at cpan.org>
-#
-#  This module is free software; you can redistribute it and/or modify it
-#  under the same terms as Perl itself.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-#
-#  $Id: ComparablePrimaryKey.pm,v 1.3 2001/09/14 12:34:36 ftobin Exp $
-#
-
-package GnuPG::ComparablePrimaryKey;
-
-use strict;
-use GnuPG::ComparableSubKey;
-
-use base qw( GnuPG::PrimaryKey GnuPG::ComparableKey );
-
-sub _deeply_compare
-{
-    my ( $self, $other ) = @_;
-    
-    my @self_subkeys  = $self->subkeys();
-    my @other_subkeys = $other->subkeys();
-    
-    return 0 unless @self_subkeys == @other_subkeys;
-    
-    my $num_subkeys = @self_subkeys;
-    
-    for ( my $i = 0; $i < $num_subkeys; $i++ )
-    {
-	my $subkey1 = $self_subkeys[$i];
-	my $subkey2 = $other_subkeys[$i];
-	
-	bless $subkey1, 'GnuPG::ComparableSubKey';
-	
-	return 0 unless $subkey1->compare( $subkey2, 1 );
-    }
-    
-    # don't compare user id's because their ordering
-    # is not necessarily deterministic
-    
-    $self->SUPER::_deeply_compare( $other );
-    
-    return 1;
-}
-
-1;
diff --git a/t/GnuPG/ComparableSubKey.pm b/t/GnuPG/ComparableSubKey.pm
deleted file mode 100644
index ef537f8..0000000
--- a/t/GnuPG/ComparableSubKey.pm
+++ /dev/null
@@ -1,51 +0,0 @@
-#  ComparableSubKey.pm
-#    - comparable GnuPG::SubKey
-#
-#  Copyright (C) 2000 Frank J. Tobin <ftobin at cpan.org>
-#
-#  This module is free software; you can redistribute it and/or modify it
-#  under the same terms as Perl itself.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-#
-#  $Id: ComparableSubKey.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $
-#
-
-package GnuPG::ComparableSubKey;
-
-use strict;
-use GnuPG::Fingerprint;
-
-use base qw( GnuPG::SubKey GnuPG::ComparableKey );
-
-sub compare
-{
-    my ( $self, $other, $deep ) = @_;
-    
-    if ( $deep )
-    {
-	bless $self->fingerprint, 'GnuPG::Fingerprint'
-	  if $self->fingerprint();
-	
-	foreach my $field ( qw( fingerprint ) )
-	{
-	    my $f1 = $self->$field();
-	    my $f2 = $other->$field();
-	    
-	    # if neither are filled in, don't compare this
-	    next if not $f1 or not $f2;
-	    
-	    # if one is filled in, but not the other
-	    # we say they are different
-	    return 0 if $f1 xor $f2;
-	    
-	    $f1->compare( $f2, 1 );
-	}
-    }
-    
-    return $self->SUPER::compare( $other, $deep )
-}
-
-1;
diff --git a/t/get_public_keys.t b/t/get_public_keys.t
index 61c475f..0949172 100644
--- a/t/get_public_keys.t
+++ b/t/get_public_keys.t
@@ -10,8 +10,8 @@ use lib './t';
 use MyTest;
 use MyTestSpecific;
 
-use GnuPG::ComparablePrimaryKey;
-use GnuPG::ComparableSubKey;
+use GnuPG::PrimaryKey;
+use GnuPG::SubKey;
 
 my ( $given_key, $handmade_key );
 
@@ -25,14 +25,13 @@ TEST
     
     $given_key = shift @returned_keys;
     
-    $handmade_key = GnuPG::ComparablePrimaryKey->new
+    $handmade_key = GnuPG::PrimaryKey->new
       ( length                 => 1024,
 	algo_num               => 17,
 	hex_id                 => '53AE596EF950DA9C',
         creation_date          => 949813093,
 	creation_date_string   => '2000-02-06',
-	expiration_date_string => '2002-02-05',
-	owner_trust            => 'f',
+	owner_trust            => '-',
         usage_flags            => 'scaESCA',
       );
     
@@ -42,6 +41,73 @@ TEST
 			       )
       );
     
+
+    my $uid0 = GnuPG::UserId->new( as_string =>  'GnuPG test key (for testing purposes only)',
+                                   validity => '-');
+    $uid0->push_signatures(
+      GnuPG::Signature->new(
+                            date => 1177086597,
+                            algo_num => 17,
+                            is_exportable => 1,
+                            user_id_string => 'GnuPG test key (for testing purposes only)',
+                            date_string => '2007-04-20',
+                            hex_id => '53AE596EF950DA9C',
+                            sig_class => 0x13,
+                            validity => '!'),
+      GnuPG::Signature->new(
+                            date => 953180097,
+                            algo_num => 17,
+                            is_exportable => 1,
+                            user_id_string => 'Frank J. Tobin <ftobin at neverending.org>',
+                            date_string => '2000-03-16',
+                            hex_id => '56FFD10A260C4FA3',
+                            sig_class => 0x10,
+                            validity => '!'),
+      GnuPG::Signature->new(
+                            date => 949813093,
+                            algo_num => 17,
+                            is_exportable => 1,
+                            user_id_string => 'GnuPG test key (for testing purposes only)',
+                            date_string => '2000-02-06',
+                            hex_id => '53AE596EF950DA9C',
+                            sig_class => 0x13,
+                            validity => '!'));
+
+    my $uid1 = GnuPG::UserId->new( as_string =>  'Foo Bar (1)',
+                                   validity => '-');
+    $uid1->push_signatures(
+      GnuPG::Signature->new(
+                            date => 1177086330,
+                            algo_num => 17,
+                            is_exportable => 1,
+                            user_id_string => 'GnuPG test key (for testing purposes only)',
+                            date_string => '2007-04-20',
+                            hex_id => '53AE596EF950DA9C',
+                            sig_class => 0x13,
+                            validity => '!'),
+      GnuPG::Signature->new(
+                            date => 953180103,
+                            algo_num => 17,
+                            is_exportable => 1,
+                            user_id_string => 'Frank J. Tobin <ftobin at neverending.org>',
+                            date_string => '2000-03-16',
+                            hex_id => '56FFD10A260C4FA3',
+                            sig_class => 0x10,
+                            validity => '!'),
+      GnuPG::Signature->new(
+                            date => 953179891,
+                            algo_num => 17,
+                            is_exportable => 1,
+                            user_id_string => 'GnuPG test key (for testing purposes only)',
+                            date_string => '2000-03-16',
+                            hex_id => '53AE596EF950DA9C',
+                            sig_class => 0x13,
+                            validity => '!'));
+
+
+
+    $handmade_key->push_user_ids($uid0, $uid1);
+
     my $subkey_signature = GnuPG::Signature->new
       ( validity       => '!',
         algo_num       => 17,
@@ -94,7 +160,6 @@ TEST
 	hex_id                   => 'ADB99D9C2E854A6B',
         creation_date            => 949813119,
 	creation_date_string     => '2000-02-06',
-	expiration_date_string   => '2002-02-05',
         usage_flags              => 'e',
       );
     
@@ -117,7 +182,7 @@ TEST
     my $subkey1 = $given_key->subkeys()->[0];
     my $subkey2 = $handmade_key->subkeys()->[0];
     
-    bless $subkey1, 'GnuPG::ComparableSubKey';
+    bless $subkey1, 'GnuPG::SubKey';
 
     my $equal = $subkey1->compare( $subkey2 );
     
diff --git a/t/get_secret_keys.t b/t/get_secret_keys.t
index 342a68d..acfeaa2 100644
--- a/t/get_secret_keys.t
+++ b/t/get_secret_keys.t
@@ -10,7 +10,7 @@ use lib './t';
 use MyTest;
 use MyTestSpecific;
 
-use GnuPG::ComparablePrimaryKey;
+use GnuPG::PrimaryKey;
 
 my ( $given_key, $handmade_key );
 
@@ -24,14 +24,13 @@ TEST
     
     $given_key = shift @returned_keys;
     
-    $handmade_key = GnuPG::ComparablePrimaryKey->new
+    $handmade_key = GnuPG::PrimaryKey->new
       ( length                 => 1024,
 	algo_num               => 17,
 	hex_id                 => '53AE596EF950DA9C',
         creation_date          => 949813093,
 	creation_date_string   => '2000-02-06',
-	expiration_date_string => '2002-02-05',
-	owner_trust            => 'f',
+	owner_trust            => '', # secret keys do not report ownertrust?
         usage_flags            => 'scaESCA',
       );
     
@@ -40,7 +39,14 @@ TEST
 				 '93AFC4B1B0288A104996B44253AE596EF950DA9C',
 			       )
       );
-    
+
+    $handmade_key->push_user_ids(
+      GnuPG::UserId->new( as_string => 'GnuPG test key (for testing purposes only)',
+                          validity => ''), # secret keys do not report uid validity?
+      GnuPG::UserId->new( as_string => 'Foo Bar (1)',
+                          validity => '')); # secret keys do not report uid validity?
+
+
     my $subkey = GnuPG::SubKey->new
       ( validity                 => 'u',
 	length                   => 768,
@@ -48,7 +54,6 @@ TEST
 	hex_id                   => 'ADB99D9C2E854A6B',
         creation_date            => 949813119,
 	creation_date_string     => '2000-02-06',
-	expiration_date_string   => '2002-02-05',
         usage_flags              => 'e',
       );
     

commit e33e2d54b56ac968ea76fb120b92ec305eeea1ec
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Tue May 11 23:56:02 2010 -0400

    added GnuPG::Key->pubkey_data, a list of Math::BigInt objects reflecting the public key data for a given key

diff --git a/lib/GnuPG/Interface.pm b/lib/GnuPG/Interface.pm
index c874ff1..2d86fa1 100644
--- a/lib/GnuPG/Interface.pm
+++ b/lib/GnuPG/Interface.pm
@@ -23,6 +23,7 @@ use Fatal qw( open close pipe fcntl );
 use Class::Struct;
 use IO::Handle;
 
+use Math::BigInt try => 'GMP';
 use GnuPG::Options;
 use GnuPG::Handles;
 
@@ -381,6 +382,7 @@ sub get_keys {
         '--fixed-list-mode',
         '--with-fingerprint',
         '--with-fingerprint',
+        '--with-key-data',
     );
 
     my $stdin  = IO::Handle->new();
@@ -586,6 +588,10 @@ sub get_keys {
           # revokers should be bound to the key with signatures:
           $current_signed_item = $rvk;
         }
+        elsif ($record_type eq 'pkd') {
+          my ($pos, $size, $data) = @fields[ 1,2,3 ];
+          $current_key->pubkey_data->[$pos+0] = Math::BigInt->from_hex('0x'.$data);
+        }
         elsif ( $record_type ne 'tru' ) {
             warn "unknown record type $record_type";
         }
diff --git a/lib/GnuPG/Key.pm b/lib/GnuPG/Key.pm
index 1500d4b..fbdda52 100644
--- a/lib/GnuPG/Key.pm
+++ b/lib/GnuPG/Key.pm
@@ -39,6 +39,7 @@ has [
          signatures
          revokers
          revocations
+         pubkey_data
       )] => (
     isa       => 'ArrayRef',
     is        => 'rw',
@@ -106,14 +107,19 @@ sub compare {
       revokers
       revocations
                  );
-
+    my $i;
     foreach my $list (@lists) {
       return 0 unless @{$self->$list} == @{$other->$list};
-      for ( my $i = 0; $i < scalar(@{$self->$list}); $i++ ) {
+      for ( $i = 0; $i < scalar(@{$self->$list}); $i++ ) {
         return 0
           unless $self->$list->[$i]->compare($other->$list->[$i], $deep);
       }
     }
+
+    return 0 unless @{$self->pubkey_data} == @{$other->pubkey_data};
+    for ( $i = 0; $i < scalar(@{$self->pubkey_data}); $i++ ) {
+      return 0 unless (0 == $self->pubkey_data->[$i]->bcmp($other->pubkey_data->[$i]));
+    }
   }
   return 1;
 }
@@ -196,7 +202,21 @@ details.
 
 =item hex_data
 
-The data of the key.
+The data of the key.  WARNING: this seems to have never been
+instantiated, and should always be undef.
+
+=item pubkey_data
+
+A list of Math::BigInt objects that correspond to the public key
+material for the given key (this member is empty on secret keys).
+
+For DSA keys, the values are: prime (p), group order (q), group generator (g), y
+
+For RSA keys, the values are: modulus (n), exponent (e)
+
+For El Gamal keys, the values are: prime (p), group generator (g), y
+
+For more details, see: http://tools.ietf.org/html/rfc4880#page-42
 
 =item hex_id
 
diff --git a/t/get_public_keys.t b/t/get_public_keys.t
index 0949172..38661b7 100644
--- a/t/get_public_keys.t
+++ b/t/get_public_keys.t
@@ -24,6 +24,17 @@ TEST
     return 0 unless @returned_keys == 1;
     
     $given_key = shift @returned_keys;
+
+    my $pubkey_data = [
+     Math::BigInt->from_hex('0x'.
+      '88FCAAA5BCDCD52084D46143F44ED1715A339794641158DE03AA2092AFD3174E3DCA2CB7DF2DDC6FEDF7C3620F5A8BDAD06713E6153F8748DD76CB97305F30CBA8F8801DB47FAC11EED725F55672CB9BDAD629178A677CBB089B3E8AE0D9A9AD7741697A35F2868C62D25670994A92D810480173DC24263EEA0F103A43C0B64B'),
+     Math::BigInt->from_hex('0x'.
+      '8F2A3842C70FF17660CBB78C78FC93F534AB9A17'),
+     Math::BigInt->from_hex('0x'.
+      '83E348C2AA65F56DE84E8FDCE6DA7B0991B1C75EC8CA446FA85869A43350907BFF36BE512385E8E7E095578BB2138C04E318495873218286DE2B8C86F36EA670135434967AC798EBA28581F709F0C6B696EB512D3E561E381A06E4B5239BCC655015F9A926C74E4B859B26EAD604F208A556511A76A40EDCD9C38E6BD82CCCB4'),
+     Math::BigInt->from_hex('0x'.
+      '80DE04C85E30C9D62C13F90CFF927A84A5A59D0900B3533D4D6193FEF8C5DAEF9FF8A7D5F76B244FBC17644F50D524E0B19CD3A4B5FC2D78DAECA3FE58FA1C1A64E6C7B96C4EE618173543163A72EF954DFD593E84342699096E9CA76578AC1DE3D893BCCD0BF470CEF625FAF816A0F503EF75C18C6173E35C8675AF919E5704')
+    ];
     
     $handmade_key = GnuPG::PrimaryKey->new
       ( length                 => 1024,
@@ -33,6 +44,7 @@ TEST
 	creation_date_string   => '2000-02-06',
 	owner_trust            => '-',
         usage_flags            => 'scaESCA',
+        pubkey_data            => $pubkey_data,
       );
     
     $handmade_key->fingerprint
@@ -153,6 +165,15 @@ TEST
 	);
     $revoker->push_signatures($designated_revoker_sig);
     
+    my $subkey_pub_data = [
+     Math::BigInt->from_hex('0x'.
+      '8831982DADC4C5D05CBB01D9EAF612131DDC9C24CEA7246557679423FB0BA42F74D10D8E7F5564F6A4FB8837F8DC4A46571C19B122E6DF4B443D15197A6A22688863D0685FADB6E402316DAA9B560D1F915475364580A67E6DF0A727778A5CF3'),
+     Math::BigInt->from_hex('0x'.
+      '6'),
+     Math::BigInt->from_hex('0x'.
+      '2F3850FF130C6AC9AA0962720E86539626FAA9B67B33A74DFC0DE843FF3E90E43E2F379EE0182D914FA539CCCF5C83A20DB3A7C45E365B8A2A092E799A3DFF4AD8274EB977BAAF5B1AFB2ACB8D6F92454F01682F555565E73E56793C46EF7C3E')
+    ];
+
     my $subkey = GnuPG::SubKey->new
       ( validity                 => 'u',
 	length                   => 768,
@@ -161,8 +182,10 @@ TEST
         creation_date            => 949813119,
 	creation_date_string     => '2000-02-06',
         usage_flags              => 'e',
+        pubkey_data              => $subkey_pub_data,
       );
     
+
     $subkey->fingerprint
       ( GnuPG::Fingerprint->new( as_hex_string =>
 				 '7466B7E98C4CCB64C2CE738BADB99D9C2E854A6B'

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list