Author: toad
Date: 2006-09-27 22:06:02 +0000 (Wed, 27 Sep 2006)
New Revision: 10524

Modified:
   trunk/freenet/src/freenet/keys/FreenetURI.java
Log:
Fix KSK-based freesites?

Modified: trunk/freenet/src/freenet/keys/FreenetURI.java
===================================================================
--- trunk/freenet/src/freenet/keys/FreenetURI.java      2006-09-27 21:54:22 UTC 
(rev 10523)
+++ trunk/freenet/src/freenet/keys/FreenetURI.java      2006-09-27 22:06:02 UTC 
(rev 10524)
@@ -227,33 +227,30 @@
                }
                URI = URI.substring(atchar + 1);

-               if(keyType.equalsIgnoreCase("KSK")) {
-                       docName = URI;
-                       metaStr = null;
-                       routingKey = null;
-                       cryptoKey = null;
-                       extra = null;
-                       suggestedEdition = -1;
-                       return;
-               }
-
                // decode metaString
                Vector sv = null;
                int slash2;
                sv = new Vector();
-                       while ((slash2 = URI.lastIndexOf("/")) != -1) {
-                               String s = URI.substring(slash2 + "/".length());
-                               if (s != null)
-                                       sv.addElement(s);
-                               URI = URI.substring(0, slash2);
-                       }
-               boolean b = false;
-               if("SSK".equals(keyType) || (b="USK".equals(keyType))) {
+               while ((slash2 = URI.lastIndexOf("/")) != -1) {
+                       String s = URI.substring(slash2 + "/".length());
+                       if (s != null)
+                               sv.addElement(s);
+                       URI = URI.substring(0, slash2);
+               }
+               
+               // sv is *backwards*
+               // this makes for more efficient handling
+               
+               boolean isSSK = "SSK".equals(keyType);
+               boolean isUSK = "USK".equals(keyType);
+               boolean isKSK = "KSK".equals(keyType);
+               
+               if(isSSK || isUSK) {

                        if(sv.isEmpty())
-                               throw new MalformedURLException("No docname");
+                               throw new MalformedURLException("No docname for 
"+keyType);
                        docName = (String) sv.remove(sv.size()-1);
-                       if(b) {
+                       if(isUSK) {
                                if(sv.isEmpty()) throw new 
MalformedURLException("No suggested edition number for USK");
                                try {
                                        suggestedEdition = 
Long.parseLong((String)sv.remove(sv.size()-1));
@@ -264,6 +261,12 @@
                                }
                        } else
                                suggestedEdition = -1;
+               } else if(isKSK) {
+                       // Deal with KSKs
+                       if(sv.isEmpty())
+                               throw new MalformedURLException("No docname for 
KSK");
+                       docName = (String) sv.remove(sv.size()-1);
+                       suggestedEdition = -1;
                } else {
                        // docName not necessary, nor is it supported, for CHKs.
                        docName = null;
@@ -278,6 +281,11 @@
                        metaStr = null;
                }

+               if(isKSK) {
+                       routingKey = extra = cryptoKey = null;
+                       return;
+               }
+               
         // strip 'file extensions' from CHKs
         // added by aum (david at rebirthing.co.nz)
         if ("CHK".equals(keyType)) {


Reply via email to