[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-lib/master] Rename two parse* methods to verify*.



commit 0236dc77715c272e7201e6111b98fbe4af747a4b
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon Jun 19 11:42:18 2017 +0200

    Rename two parse* methods to verify*.
---
 .../torproject/descriptor/impl/ExtraInfoDescriptorImpl.java |  2 +-
 .../org/torproject/descriptor/impl/MicrodescriptorImpl.java |  4 ++--
 .../torproject/descriptor/impl/NetworkStatusEntryImpl.java  |  6 +++---
 .../java/org/torproject/descriptor/impl/ParseHelper.java    | 13 +++++++++++--
 .../torproject/descriptor/impl/ServerDescriptorImpl.java    |  4 ++--
 5 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index 0d67af9..ca7d376 100644
--- a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -828,7 +828,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
     if (partsNoOpt.length != 2) {
       throw new DescriptorParseException("Illegal line '" + line + "'.");
     }
-    ParseHelper.parseThirtyTwoByteBase64String(line, partsNoOpt[1]);
+    ParseHelper.verifyThirtyTwoByteBase64String(line, partsNoOpt[1]);
     this.setDigestSha256Base64(partsNoOpt[1]);
   }
 
diff --git a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index 65c20d4..c436120 100644
--- a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -198,11 +198,11 @@ public class MicrodescriptorImpl extends DescriptorImpl
     } else {
       switch (parts[1]) {
         case "ed25519":
-          ParseHelper.parseThirtyTwoByteBase64String(line, parts[2]);
+          ParseHelper.verifyThirtyTwoByteBase64String(line, parts[2]);
           this.ed25519Identity = parts[2];
           break;
         case "rsa1024":
-          ParseHelper.parseTwentyByteBase64String(line, parts[2]);
+          ParseHelper.verifyTwentyByteBase64String(line, parts[2]);
           this.rsa1024Identity = parts[2];
           break;
         default:
diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index 337f0b2..64c688e 100644
--- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -266,11 +266,11 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
       this.microdescriptorDigests = new HashSet<>();
     }
     if (parts.length == 2) {
-      ParseHelper.parseThirtyTwoByteBase64String(line, parts[1]);
+      ParseHelper.verifyThirtyTwoByteBase64String(line, parts[1]);
       this.microdescriptorDigests.add(parts[1]);
     } else if (parts.length == 3 && parts[2].length() > 7) {
       /* 7 == "sha256=".length() */
-      ParseHelper.parseThirtyTwoByteBase64String(line,
+      ParseHelper.verifyThirtyTwoByteBase64String(line,
           parts[2].substring(7));
       this.microdescriptorDigests.add(parts[2].substring(7));
     }
@@ -283,7 +283,7 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
     } else if ("none".equals(parts[2])) {
       this.masterKeyEd25519 = "none";
     } else {
-      ParseHelper.parseThirtyTwoByteBase64String(line, parts[2]);
+      ParseHelper.verifyThirtyTwoByteBase64String(line, parts[2]);
       this.masterKeyEd25519 = parts[2];
     }
   }
diff --git a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
index dec33f5..1c7aa93 100644
--- a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
@@ -21,6 +21,15 @@ import java.util.regex.Pattern;
 
 import javax.xml.bind.DatatypeConverter;
 
+/**
+ * Parse helper for descriptor contents.
+ *
+ * <p>Naming convention: methods starting with {@code parse} return valid and
+ * sometimes changed data items (e.g. string to port int), methods starting with
+ * {@code verify} only check data items without returning them, and methods
+ * starting with {@code convert} return checked and explicitly changed data
+ * items (e.g. base64 to hex encoding).</p>
+ */
 public class ParseHelper {
 
   private static Pattern keywordPattern = Pattern.compile("^[A-Za-z0-9-]+$");
@@ -281,7 +290,7 @@ public class ParseHelper {
   private static Pattern twentyByteBase64Pattern =
       Pattern.compile("^[0-9a-zA-Z+/]{27}$");
 
-  protected static void parseTwentyByteBase64String(String line,
+  protected static void verifyTwentyByteBase64String(String line,
       String base64String) throws DescriptorParseException {
     convertTwentyByteBase64StringToHex(line, base64String);
   }
@@ -301,7 +310,7 @@ public class ParseHelper {
   private static Pattern thirtyTwoByteBase64Pattern =
       Pattern.compile("^[0-9a-zA-Z+/]{43}$");
 
-  protected static void parseThirtyTwoByteBase64String(String line,
+  protected static void verifyThirtyTwoByteBase64String(String line,
       String base64String) throws DescriptorParseException {
     convertThirtyTwoByteBase64StringToHex(line, base64String);
   }
diff --git a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index 428b2f0..d438702 100644
--- a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -467,7 +467,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
     this.extraInfoDigest = ParseHelper.parseTwentyByteHexString(line,
         partsNoOpt[1]);
     if (partsNoOpt.length >= 3) {
-      ParseHelper.parseThirtyTwoByteBase64String(line, partsNoOpt[2]);
+      ParseHelper.verifyThirtyTwoByteBase64String(line, partsNoOpt[2]);
       this.extraInfoDigestSha256 = partsNoOpt[2];
     }
   }
@@ -671,7 +671,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
     if (partsNoOpt.length != 2) {
       throw new DescriptorParseException("Illegal line '" + line + "'.");
     }
-    ParseHelper.parseThirtyTwoByteBase64String(line, partsNoOpt[1]);
+    ParseHelper.verifyThirtyTwoByteBase64String(line, partsNoOpt[1]);
     this.setDigestSha256Base64(partsNoOpt[1]);
   }
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits