Commit 82f555ee authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Fix encoding of Microdescriptor's getDigestSha256Base64().

parent 823fa496
......@@ -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
......
......@@ -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. */
......
......@@ -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)
......
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