[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/release] Replace JAXB with Apache Commons Codec dependency.
commit d1f9a329a2e03662691b96d58dd209e145fe4835
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed Jul 4 17:29:19 2018 +0200
Replace JAXB with Apache Commons Codec dependency.
The reason is that JAXB won't be part of standard Java 9 anymore, and
the only reason why we used it was to get rid of Apache Commons Codec
as dependency, three years ago. Now it makes sense to just go back to
Apache Commons Codec in preparation of upgrading to Java 9.
Partially reverts 1734d16.
Fixes #25444.
---
CHANGELOG.md | 9 +++++++++
build.xml | 1 +
.../org/torproject/descriptor/impl/DescriptorImpl.java | 9 +++++----
.../org/torproject/descriptor/impl/ParseHelper.java | 18 ++++++++----------
4 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 39257fe..0e9ad5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+# Changes in version 2.5.0 - 2018-??-??
+
+ * Medium changes
+ - Go back to using Apache Commons Codec as base64 and hexadecimal
+ codec rather than using JAXB which won't be available anymore
+ after upgrading from Java 8 to 9. Applications must provide
+ Apache Commons Codec 1.10 as dependency.
+
+
# Changes in version 2.4.0 - 2018-05-23
* Medium changes
diff --git a/build.xml b/build.xml
index 3c4bf28..f84c507 100644
--- a/build.xml
+++ b/build.xml
@@ -14,6 +14,7 @@
<property name="jarpatternprop" value="empty" />
<patternset id="runtime" >
+ <include name="commons-codec-1.10.jar"/>
<include name="commons-compress-1.13.jar"/>
<include name="jackson-annotations-2.8.6.jar"/>
<include name="jackson-core-2.8.6.jar"/>
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java
index 918fef8..a6acee7 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java
@@ -6,6 +6,9 @@ package org.torproject.descriptor.impl;
import org.torproject.descriptor.Descriptor;
import org.torproject.descriptor.DescriptorParseException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStreamReader;
@@ -19,8 +22,6 @@ import java.util.Map;
import java.util.Scanner;
import java.util.Set;
-import javax.xml.bind.DatatypeConverter;
-
public abstract class DescriptorImpl implements Descriptor {
public static final String NL = "\n";
@@ -383,7 +384,7 @@ public abstract class DescriptorImpl implements Descriptor {
end = ascii.indexOf(endToken) + endToken.length();
}
if (start >= 0 && end >= 0 && end > start) {
- this.digestSha1Hex = DatatypeConverter.printHexBinary(
+ this.digestSha1Hex = Hex.encodeHexString(
messageDigest("SHA-1", start, end)).toLowerCase();
}
}
@@ -426,7 +427,7 @@ public abstract class DescriptorImpl implements Descriptor {
end = ascii.indexOf(endToken) + endToken.length();
}
if (start >= 0 && end >= 0 && end > start) {
- this.digestSha256Base64 = DatatypeConverter.printBase64Binary(
+ this.digestSha256Base64 = Base64.encodeBase64String(
messageDigest("SHA-256", start, end)).replaceAll("=", "");
}
}
diff --git a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
index d0c83f0..49a3430 100644
--- a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
@@ -5,6 +5,9 @@ package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -19,8 +22,6 @@ import java.util.TreeMap;
import java.util.TreeSet;
import java.util.regex.Pattern;
-import javax.xml.bind.DatatypeConverter;
-
/**
* Parse helper for descriptor contents.
*
@@ -302,8 +303,7 @@ public class ParseHelper {
+ "' in line '" + line + "' is not a valid base64-encoded "
+ "20-byte value.");
}
- return DatatypeConverter.printHexBinary(
- DatatypeConverter.parseBase64Binary(base64String + "="))
+ return Hex.encodeHexString(Base64.decodeBase64(base64String + "="))
.toUpperCase();
}
@@ -322,8 +322,7 @@ public class ParseHelper {
+ "' in line '" + line + "' is not a valid base64-encoded "
+ "32-byte value.");
}
- return DatatypeConverter.printHexBinary(
- DatatypeConverter.parseBase64Binary(base64String + "="))
+ return Hex.encodeHexString(Base64.decodeBase64(base64String + "="))
.toUpperCase();
}
@@ -457,8 +456,7 @@ public class ParseHelper {
.substring(beginEd25519CertLine.length(),
identityEd25519CryptoBlock.length()
- endEd25519CertLine.length()).replaceAll("=", "");
- byte[] identityEd25519 = DatatypeConverter.parseBase64Binary(
- identityEd25519Base64);
+ byte[] identityEd25519 = Base64.decodeBase64(identityEd25519Base64);
if (identityEd25519.length < 40) {
throw new DescriptorParseException("Invalid length of "
+ "identity-ed25519 (in bytes): " + identityEd25519.length);
@@ -494,8 +492,8 @@ public class ParseHelper {
byte[] masterKeyEd25519 = new byte[32];
System.arraycopy(identityEd25519, extensionStart + 4,
masterKeyEd25519, 0, masterKeyEd25519.length);
- String masterKeyEd25519Base64 = DatatypeConverter
- .printBase64Binary(masterKeyEd25519).replaceAll("=", "");
+ String masterKeyEd25519Base64
+ = Base64.encodeBase64String(masterKeyEd25519).replaceAll("=", "");
String masterKeyEd25519Base64NoTrailingEqualSigns =
masterKeyEd25519Base64.replaceAll("=", "");
return masterKeyEd25519Base64NoTrailingEqualSigns;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits