Author: j16sdiz
Date: 2008-12-04 11:54:41 +0000 (Thu, 04 Dec 2008)
New Revision: 24036

Modified:
   trunk/freenet/src/freenet/keys/FreenetURI.java
Log:
some helper methods

Modified: trunk/freenet/src/freenet/keys/FreenetURI.java
===================================================================
--- trunk/freenet/src/freenet/keys/FreenetURI.java      2008-12-04 10:42:09 UTC 
(rev 24035)
+++ trunk/freenet/src/freenet/keys/FreenetURI.java      2008-12-04 11:54:41 UTC 
(rev 24036)
@@ -845,9 +845,33 @@
        public URI toURI(String basePath) throws URISyntaxException {
                return new URI(basePath + toString(false, false));
        }
+       
+       public boolean isSSK() {
+               return "SSK".equals(keyType);
+       }
 
+       public boolean isUSK() {
+               return "USK".equals(keyType);
+       }
+
+       public boolean isCHK() {
+               return "CHK".equals(keyType);
+       }
+
        public FreenetURI sskForUSK() {
                if(!keyType.equalsIgnoreCase("USK")) throw new 
IllegalStateException();
                return new FreenetURI("SSK", docName+"-"+suggestedEdition, 
metaStr, routingKey, cryptoKey, extra, 0);
        }
-}
+
+       public FreenetURI uskForSSK() {
+               if(!keyType.equalsIgnoreCase("SSK")) throw new 
IllegalStateException();
+               if (!docName.matches(".*\\-[0-9]+"))
+                       throw new IllegalStateException();
+
+               int offset = docName.lastIndexOf('-');
+               String siteName = docName.substring(0, offset);
+               long edition = Long.valueOf(docName.substring(offset + 1, 
docName.length()));
+
+               return new FreenetURI("USK", siteName, metaStr, routingKey, 
cryptoKey, extra, edition);
+       }
+}
\ No newline at end of file

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to