[tor-commits] [metrics-lib/release] Change encoding of microdescriptor digests in network status entries.

karsten at torproject.org karsten at torproject.org
Wed Jun 21 12:20:54 UTC 2017


commit de9600a5dc937c4c453ed261266f38f21978f61e
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Sat Jun 17 21:20:01 2017 +0200

    Change encoding of microdescriptor digests in network status entries.
    
    Fixes #22640.
---
 CHANGELOG.md                                               |  8 ++++++++
 .../java/org/torproject/descriptor/NetworkStatusEntry.java | 12 ++++++------
 .../torproject/descriptor/impl/NetworkStatusEntryImpl.java | 14 +++++++-------
 .../java/org/torproject/descriptor/impl/ParseHelper.java   | 14 ++++++++++++--
 4 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 409d0e8..e79811a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+# Changes in version 1.9.0 - 2017-06-??
+
+ * Minor changes
+   - Fix a bug where NetworkStatusEntry's getMicrodescriptorDigests()
+     and getMicrodescriptorDigestsSha256Base64() return hex strings
+     rather than base64 strings.
+
+
 # Changes in version 1.8.2 - 2017-06-16
 
  * Medium changes
diff --git a/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java b/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java
index c59eab9..9c5dae5 100644
--- a/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java
+++ b/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java
@@ -89,9 +89,9 @@ public interface NetworkStatusEntry {
   public int getDirPort();
 
   /**
-   * Return the (possibly empty) set of microdescriptor digests if the
-   * containing network status is a vote or microdesc consensus, or null
-   * otherwise.
+   * Return the (possibly empty) set of microdescriptor digests, encoded as 43
+   * base64 characters without padding characters, if the containing network
+   * status is a vote or microdesc consensus, or null otherwise.
    *
    * @deprecated Renamed to {@link #getMicrodescriptorDigestsSha256Base64()}.
    *
@@ -100,9 +100,9 @@ public interface NetworkStatusEntry {
   public Set<String> getMicrodescriptorDigests();
 
   /**
-   * Return the (possibly empty) set of microdescriptor digests if the
-   * containing network status is a vote or microdesc consensus, or null
-   * otherwise.
+   * Return the (possibly empty) set of microdescriptor digests, encoded as 43
+   * base64 characters without padding characters, if the containing network
+   * status is a vote or microdesc consensus, or null otherwise.
    *
    * @since 1.7.0
    */
diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index 987b530..337f0b2 100644
--- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -141,11 +141,11 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
           + "fewer space-separated elements than expected.");
     }
     this.nickname = ParseHelper.parseNickname(line, parts[1]);
-    this.fingerprint = ParseHelper.parseTwentyByteBase64String(line,
+    this.fingerprint = ParseHelper.convertTwentyByteBase64StringToHex(line,
         parts[2]);
     int descriptorOffset = 0;
     if (!this.microdescConsensus) {
-      this.descriptor = ParseHelper.parseTwentyByteBase64String(line,
+      this.descriptor = ParseHelper.convertTwentyByteBase64StringToHex(line,
           parts[3]);
       descriptorOffset = 1;
     }
@@ -266,13 +266,13 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
       this.microdescriptorDigests = new HashSet<>();
     }
     if (parts.length == 2) {
-      this.microdescriptorDigests.add(
-          ParseHelper.parseThirtyTwoByteBase64String(line, parts[1]));
+      ParseHelper.parseThirtyTwoByteBase64String(line, parts[1]);
+      this.microdescriptorDigests.add(parts[1]);
     } else if (parts.length == 3 && parts[2].length() > 7) {
       /* 7 == "sha256=".length() */
-      this.microdescriptorDigests.add(
-          ParseHelper.parseThirtyTwoByteBase64String(line,
-          parts[2].substring(7)));
+      ParseHelper.parseThirtyTwoByteBase64String(line,
+          parts[2].substring(7));
+      this.microdescriptorDigests.add(parts[2].substring(7));
     }
   }
 
diff --git a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
index 31454e5..dec33f5 100644
--- a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
@@ -281,7 +281,12 @@ public class ParseHelper {
   private static Pattern twentyByteBase64Pattern =
       Pattern.compile("^[0-9a-zA-Z+/]{27}$");
 
-  protected static String parseTwentyByteBase64String(String line,
+  protected static void parseTwentyByteBase64String(String line,
+      String base64String) throws DescriptorParseException {
+    convertTwentyByteBase64StringToHex(line, base64String);
+  }
+
+  protected static String convertTwentyByteBase64StringToHex(String line,
       String base64String) throws DescriptorParseException {
     if (!twentyByteBase64Pattern.matcher(base64String).matches()) {
       throw new DescriptorParseException("'" + base64String
@@ -296,7 +301,12 @@ public class ParseHelper {
   private static Pattern thirtyTwoByteBase64Pattern =
       Pattern.compile("^[0-9a-zA-Z+/]{43}$");
 
-  protected static String parseThirtyTwoByteBase64String(String line,
+  protected static void parseThirtyTwoByteBase64String(String line,
+      String base64String) throws DescriptorParseException {
+    convertThirtyTwoByteBase64StringToHex(line, base64String);
+  }
+
+  private static String convertThirtyTwoByteBase64StringToHex(String line,
       String base64String) throws DescriptorParseException {
     if (!thirtyTwoByteBase64Pattern.matcher(base64String).matches()) {
       throw new DescriptorParseException("'" + base64String





More information about the tor-commits mailing list