Commit de9600a5 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Change encoding of microdescriptor digests in network status entries.

Fixes #22640.
parent 47a69b34
# 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
......
......@@ -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
*/
......
......@@ -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));
}
}
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment