[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/release] Fix encoding of Microdescriptor's getDigestSha256Base64().
commit 82f555ee3568193460811f0a20a0f22c334c3b4a
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon May 29 13:47:57 2017 +0200
Fix encoding of Microdescriptor's getDigestSha256Base64().
---
CHANGELOG.md | 2 ++
.../java/org/torproject/descriptor/impl/MicrodescriptorImpl.java | 4 ++--
.../org/torproject/descriptor/impl/MicrodescriptorImplTest.java | 6 +++++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3ab6955..61be7dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@
and maps to avoid repeating string literals and to use more speedy
collection types.
- Simplify and avoid repetition in parse helper methods.
+ - Fix a bug where Microdescriptor's getDigestSha256Base64() returns
+ a hex string rather than a base64 string.
# Changes in version 1.7.0 - 2017-05-17
diff --git a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index e8329cc..522da05 100644
--- a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -243,9 +243,9 @@ public class MicrodescriptorImpl extends DescriptorImpl
byte[] forDigest = new byte[end - start];
System.arraycopy(this.getRawDescriptorBytes(), start,
forDigest, 0, end - start);
- this.microdescriptorDigest = DatatypeConverter.printHexBinary(
+ this.microdescriptorDigest = DatatypeConverter.printBase64Binary(
MessageDigest.getInstance("SHA-256").digest(forDigest))
- .toLowerCase();
+ .replaceAll("=", "");
}
} catch (UnsupportedEncodingException e) {
/* Handle below. */
diff --git a/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
index 20b0849..d9040f3 100644
--- a/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
@@ -3,6 +3,8 @@
package org.torproject.descriptor.impl;
+import static org.junit.Assert.assertEquals;
+
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.Microdescriptor;
@@ -57,7 +59,9 @@ public class MicrodescriptorImplTest {
@Test()
public void testDefaults() throws DescriptorParseException {
- DescriptorBuilder.createWithDefaultLines();
+ Microdescriptor micro = DescriptorBuilder.createWithDefaultLines();
+ assertEquals("ER1AC4KqT//o3pJDrqlmej5G2qW1EQYEr/IrMQHNc6I",
+ micro.getDigestSha256Base64());
}
@Test(expected = DescriptorParseException.class)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits