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

[tor-commits] [metrics-lib/master] Fix legacy-dir-key line parsing in votes.



commit 8664260c1f63381d81ebdd5fddeedb300afe29d5
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Fri Feb 17 07:48:53 2012 +0100

    Fix legacy-dir-key line parsing in votes.
---
 .../descriptor/RelayNetworkStatusVote.java         |    6 ++--
 .../impl/RelayNetworkStatusVoteImpl.java           |   14 +++++-----
 .../impl/RelayNetworkStatusVoteImplTest.java       |   24 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/src/org/torproject/descriptor/RelayNetworkStatusVote.java b/src/org/torproject/descriptor/RelayNetworkStatusVote.java
index 3dd82bc..f9635e2 100644
--- a/src/org/torproject/descriptor/RelayNetworkStatusVote.java
+++ b/src/org/torproject/descriptor/RelayNetworkStatusVote.java
@@ -68,9 +68,9 @@ public interface RelayNetworkStatusVote extends Descriptor {
   /* Return the directory key certificate version. */
   public int getDirKeyCertificateVersion();
 
-  /* Return the legacy key or null if the directory authority does not use
-   * a legacy key. */
-  public String getLegacyKey();
+  /* Return the legacy dir key or null if the directory authority does not
+   * use a legacy dir key. */
+  public String getLegacyDirKey();
 
   /* Return the directory key publication timestamp. */
   public long getDirKeyPublishedMillis();
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
index 3729f75..a00cd75 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
@@ -255,8 +255,8 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
           this.parseDirAddressLine(line, parts);
         } else if (keyword.equals("fingerprint")) {
           this.parseFingerprintLine(line, parts);
-        } else if (keyword.equals("legacy-key")) {
-          this.parseLegacyKeyLine(line, parts);
+        } else if (keyword.equals("legacy-dir-key")) {
+          this.parseLegacyDirKeyLine(line, parts);
         } else if (keyword.equals("dir-key-published")) {
           this.parseDirKeyPublished(line, parts);
         } else if (keyword.equals("dir-key-expires")) {
@@ -349,12 +349,12 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
     ParseHelper.parseTwentyByteHexString(line, parts[1]);
   }
 
-  private void parseLegacyKeyLine(String line, String[] parts)
+  private void parseLegacyDirKeyLine(String line, String[] parts)
       throws DescriptorParseException {
     if (parts.length != 2) {
       throw new DescriptorParseException("Illegal line '" + line + "'.");
     }
-    this.legacyKey = ParseHelper.parseTwentyByteHexString(line, parts[2]);
+    this.legacyDirKey = ParseHelper.parseTwentyByteHexString(line, parts[1]);
   }
 
   private void parseDirKeyPublished(String line, String[] parts)
@@ -430,9 +430,9 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
     return this.dirKeyCertificateVersion;
   }
 
-  private String legacyKey;
-  public String getLegacyKey() {
-    return this.legacyKey;
+  private String legacyDirKey;
+  public String getLegacyDirKey() {
+    return this.legacyDirKey;
   }
 
   private long dirKeyPublishedMillis;
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index e907086..8a60eec 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -146,6 +146,14 @@ public class RelayNetworkStatusVoteImplTest {
       vb.contactLine = line;
       return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
     }
+    private String legacyDirKeyLine = null;
+    private static RelayNetworkStatusVote
+        createWithLegacyDirKeyLine(String line)
+        throws DescriptorParseException {
+      VoteBuilder vb = new VoteBuilder();
+      vb.legacyDirKeyLine = line;
+      return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
+    }
     private String dirKeyCertificateVersionLine =
         "dir-key-certificate-version 3";
     private static RelayNetworkStatusVote
@@ -394,6 +402,9 @@ public class RelayNetworkStatusVoteImplTest {
       if (this.contactLine != null) {
         sb.append(this.contactLine + "\n");
       }
+      if (this.legacyDirKeyLine != null) {
+        sb.append(this.legacyDirKeyLine + "\n");
+      }
       if (this.dirKeyCertificateVersionLine != null) {
         sb.append(this.dirKeyCertificateVersionLine + "\n");
       }
@@ -902,6 +913,19 @@ public class RelayNetworkStatusVoteImplTest {
         + "Appelbaum <jacob@xxxxxxxxxxxxx>");
   }
 
+  @Test()
+  public void testLegacyDirKeyLine() throws DescriptorParseException {
+    RelayNetworkStatusVote vote = VoteBuilder.createWithLegacyDirKeyLine(
+        "legacy-dir-key 81349FC1F2DBA2C2C11B45CB9706637D480AB913");
+    assertEquals("81349FC1F2DBA2C2C11B45CB9706637D480AB913",
+        vote.getLegacyDirKey());
+  }
+
+  @Test(expected = DescriptorParseException.class)
+  public void testLegacyDirKeyLineNoId() throws DescriptorParseException {
+    VoteBuilder.createWithLegacyDirKeyLine("legacy-dir-key ");
+  }
+
   @Test(expected = DescriptorParseException.class)
   public void testDirKeyCertificateVersionLineMissing()
       throws DescriptorParseException {



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