Commit 1734d166 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Remove commons-codec dependency.

Turns out that Java already comes with default implementations of
SHA-1, SHA-256, and Base64 that we can use.
parent 2237e893
......@@ -8,7 +8,6 @@
<path id="classpath">
<pathelement path="${classes}"/>
<fileset dir="/usr/share/java">
<include name="commons-codec.jar"/>
<include name="commons-compress.jar"/>
<include name="junit4.jar"/>
</fileset>
......
......@@ -2,8 +2,9 @@
* See LICENSE for licensing information */
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
......@@ -11,7 +12,9 @@ import java.util.List;
import java.util.Scanner;
import java.util.Set;
import org.apache.commons.codec.digest.DigestUtils;
import javax.xml.bind.DatatypeConverter;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.DirectoryKeyCertificate;
/* TODO Add test class. */
......@@ -203,10 +206,13 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
byte[] forDigest = new byte[sig - start];
System.arraycopy(this.getRawDescriptorBytes(), start,
forDigest, 0, sig - start);
this.certificateDigest = DigestUtils.shaHex(forDigest);
this.certificateDigest = DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-1").digest(forDigest));
}
} catch (UnsupportedEncodingException e) {
/* Handle below. */
} catch (NoSuchAlgorithmException e) {
/* Handle below. */
}
if (this.certificateDigest == null) {
throw new DescriptorParseException("Could not calculate "
......
......@@ -2,8 +2,9 @@
* See LICENSE for licensing information */
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
......@@ -15,8 +16,10 @@ import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.commons.codec.digest.DigestUtils;
import javax.xml.bind.DatatypeConverter;
import org.torproject.descriptor.BandwidthHistory;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.ExtraInfoDescriptor;
public class ExtraInfoDescriptorImpl extends DescriptorImpl
......@@ -652,10 +655,13 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
byte[] forDigest = new byte[sig - start];
System.arraycopy(this.getRawDescriptorBytes(), start,
forDigest, 0, sig - start);
this.extraInfoDigest = DigestUtils.shaHex(forDigest);
this.extraInfoDigest = DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-1").digest(forDigest));
}
} catch (UnsupportedEncodingException e) {
/* Handle below. */
} catch (NoSuchAlgorithmException e) {
/* Handle below. */
}
if (this.extraInfoDigest == null) {
throw new DescriptorParseException("Could not calculate extra-info "
......
......@@ -2,8 +2,9 @@
* See LICENSE for licensing information */
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
......@@ -11,7 +12,9 @@ import java.util.List;
import java.util.Scanner;
import java.util.Set;
import org.apache.commons.codec.digest.DigestUtils;
import javax.xml.bind.DatatypeConverter;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.Microdescriptor;
/* Contains a microdescriptor. */
......@@ -203,10 +206,13 @@ public class MicrodescriptorImpl extends DescriptorImpl
byte[] forDigest = new byte[end - start];
System.arraycopy(this.getRawDescriptorBytes(), start,
forDigest, 0, end - start);
this.microdescriptorDigest = DigestUtils.sha256Hex(forDigest);
this.microdescriptorDigest = DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-256").digest(forDigest));
}
} catch (UnsupportedEncodingException e) {
/* Handle below. */
} catch (NoSuchAlgorithmException e) {
/* Handle below. */
}
if (this.microdescriptorDigest == null) {
throw new DescriptorParseException("Could not calculate "
......
......@@ -2,7 +2,6 @@
* See LICENSE for licensing information */
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -13,8 +12,9 @@ import java.util.TimeZone;
import java.util.TreeMap;
import java.util.regex.Pattern;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import javax.xml.bind.DatatypeConverter;
import org.torproject.descriptor.DescriptorParseException;
public class ParseHelper {
......@@ -270,7 +270,8 @@ public class ParseHelper {
+ "' in line '" + line + "' is not a valid base64-encoded "
+ "20-byte value.");
}
return Hex.encodeHexString(Base64.decodeBase64(base64String + "=")).
return DatatypeConverter.printHexBinary(
DatatypeConverter.parseBase64Binary(base64String + "=")).
toUpperCase();
}
......@@ -283,7 +284,8 @@ public class ParseHelper {
+ "' in line '" + line + "' is not a valid base64-encoded "
+ "32-byte value.");
}
return Hex.encodeHexString(Base64.decodeBase64(base64String + "=")).
return DatatypeConverter.printHexBinary(
DatatypeConverter.parseBase64Binary(base64String + "=")).
toUpperCase();
}
......
......@@ -2,8 +2,9 @@
* See LICENSE for licensing information */
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
......@@ -11,7 +12,9 @@ import java.util.List;
import java.util.Scanner;
import java.util.Set;
import org.apache.commons.codec.digest.DigestUtils;
import javax.xml.bind.DatatypeConverter;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.RelayDirectory;
import org.torproject.descriptor.RouterStatusEntry;
import org.torproject.descriptor.ServerDescriptor;
......@@ -70,10 +73,13 @@ public class RelayDirectoryImpl extends DescriptorImpl
byte[] forDigest = new byte[sig - start];
System.arraycopy(this.getRawDescriptorBytes(), start,
forDigest, 0, sig - start);
this.directoryDigest = DigestUtils.shaHex(forDigest);
this.directoryDigest = DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-1").digest(forDigest));
}
} catch (UnsupportedEncodingException e) {
/* Handle below. */
} catch (NoSuchAlgorithmException e) {
/* Handle below. */
}
if (this.directoryDigest == null) {
throw new DescriptorParseException("Could not calculate v1 "
......
......@@ -2,8 +2,9 @@
* See LICENSE for licensing information */
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
......@@ -15,7 +16,9 @@ import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.commons.codec.digest.DigestUtils;
import javax.xml.bind.DatatypeConverter;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.RelayNetworkStatusConsensus;
/* Contains a network status consensus or microdesc consensus. */
......@@ -70,10 +73,13 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
byte[] forDigest = new byte[sig - start];
System.arraycopy(this.getRawDescriptorBytes(), start,
forDigest, 0, sig - start);
this.consensusDigest = DigestUtils.shaHex(forDigest);
this.consensusDigest = DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-1").digest(forDigest));
}
} catch (UnsupportedEncodingException e) {
/* Handle below. */
} catch (NoSuchAlgorithmException e) {
/* Handle below. */
}
if (this.consensusDigest == null) {
throw new DescriptorParseException("Could not calculate consensus "
......
......@@ -2,8 +2,9 @@
* See LICENSE for licensing information */
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
......@@ -13,7 +14,9 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.commons.codec.digest.DigestUtils;
import javax.xml.bind.DatatypeConverter;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.RelayNetworkStatus;
/* TODO Write unit tests. */
......@@ -68,10 +71,13 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
byte[] forDigest = new byte[sig - start];
System.arraycopy(this.getRawDescriptorBytes(), start,
forDigest, 0, sig - start);
this.statusDigest = DigestUtils.shaHex(forDigest);
this.statusDigest = DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-1").digest(forDigest));
}
} catch (UnsupportedEncodingException e) {
/* Handle below. */
} catch (NoSuchAlgorithmException e) {
/* Handle below. */
}
if (this.statusDigest == null) {
throw new DescriptorParseException("Could not calculate status "
......
......@@ -2,8 +2,9 @@
* See LICENSE for licensing information */
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
......@@ -11,8 +12,10 @@ import java.util.List;
import java.util.Scanner;
import java.util.Set;
import org.apache.commons.codec.digest.DigestUtils;
import javax.xml.bind.DatatypeConverter;
import org.torproject.descriptor.BandwidthHistory;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.ServerDescriptor;
/* Contains a relay server descriptor. */
......@@ -538,10 +541,13 @@ public class ServerDescriptorImpl extends DescriptorImpl
byte[] forDigest = new byte[sig - start];
System.arraycopy(this.getRawDescriptorBytes(), start,
forDigest, 0, sig - start);
this.serverDescriptorDigest = DigestUtils.shaHex(forDigest);
this.serverDescriptorDigest = DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-1").digest(forDigest));
}
} catch (UnsupportedEncodingException e) {
/* Handle below. */
} catch (NoSuchAlgorithmException e) {
/* Handle below. */
}
if (this.serverDescriptorDigest == null) {
throw new DescriptorParseException("Could not calculate server "
......
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