Author: brett
Date: Wed Jul 16 01:08:19 2008
New Revision: 677188

URL: http://svn.apache.org/viewvc?rev=677188&view=rev
Log:
just use a single key ring - this avoids the need to clean up memory when 
creating multiple copies as the collections hold a map

Modified:
    
commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java

Modified: 
commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java?rev=677188&r1=677187&r2=677188&view=diff
==============================================================================
--- 
commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java
 (original)
+++ 
commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java
 Wed Jul 16 01:08:19 2008
@@ -39,20 +39,20 @@
 public class BouncyCastleKeyRing
     implements KeyRing
 {
-    private final PGPSecretKeyRingCollection pgpSec;
+    private final PGPSecretKeyRing pgpSec;
 
     private final char[] password;
 
-    private final PGPPublicKeyRingCollection pgpPub;
+    private final PGPPublicKeyRing pgpPub;
 
     private static final long MASK = 0xFFFFFFFFL;
 
     public BouncyCastleKeyRing( InputStream secretKeyRingStream, InputStream 
publicKeyRingStream, char[] password )
         throws IOException, PGPException
     {
-        pgpSec = new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( 
secretKeyRingStream ) );
+        pgpSec = new PGPSecretKeyRing( PGPUtil.getDecoderStream( 
secretKeyRingStream ) );
 
-        pgpPub = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( 
publicKeyRingStream ) );
+        pgpPub = new PGPPublicKeyRing( PGPUtil.getDecoderStream( 
publicKeyRingStream ) );
 
         this.password = password;
     }
@@ -61,25 +61,19 @@
     {
         return password;
     }
-
+    
     public PGPSecretKey getSecretKey( String keyId )
     {
-        Iterator rIt = pgpSec.getKeyRings();
+        Iterator kIt = pgpSec.getSecretKeys();
 
-        while ( rIt.hasNext() )
+        while ( kIt.hasNext() )
         {
-            PGPSecretKeyRing kRing = (PGPSecretKeyRing) rIt.next();
-            Iterator kIt = kRing.getSecretKeys();
+            PGPSecretKey k = (PGPSecretKey) kIt.next();
 
-            while ( kIt.hasNext() )
+            // TODO: do long conversion in other direction
+            if ( k.isSigningKey() && Long.toHexString( k.getKeyID() & MASK 
).equals( keyId.toLowerCase() ) )
             {
-                PGPSecretKey k = (PGPSecretKey) kIt.next();
-
-                // TODO: do long conversion in other direction
-                if ( k.isSigningKey() && Long.toHexString( k.getKeyID() & MASK 
).equals( keyId.toLowerCase() ) )
-                {
-                    return k;
-                }
+                return k;
             }
         }
 
@@ -88,22 +82,16 @@
 
     public PGPPublicKey getPublicKey( String keyId )
     {
-        Iterator rIt = pgpPub.getKeyRings();
+        Iterator kIt = pgpPub.getPublicKeys();
 
-        while ( rIt.hasNext() )
+        while ( kIt.hasNext() )
         {
-            PGPPublicKeyRing kRing = (PGPPublicKeyRing) rIt.next();
-            Iterator kIt = kRing.getPublicKeys();
+            PGPPublicKey k = (PGPPublicKey) kIt.next();
 
-            while ( kIt.hasNext() )
+            // TODO: do long conversion in other direction
+            if ( Long.toHexString( k.getKeyID() & MASK ).equals( 
keyId.toLowerCase() ) )
             {
-                PGPPublicKey k = (PGPPublicKey) kIt.next();
-
-                // TODO: do long conversion in other direction
-                if ( Long.toHexString( k.getKeyID() & MASK ).equals( 
keyId.toLowerCase() ) )
-                {
-                    return k;
-                }
+                return k;
             }
         }
 


Reply via email to