[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-lib/master] Remove commons-codec dependency.



commit 1734d1663944acf20d275ac4f66be87d497ab7cb
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Wed Aug 5 13:53:38 2015 +0200

    Remove commons-codec dependency.
    
    Turns out that Java already comes with default implementations of
    SHA-1, SHA-256, and Base64 that we can use.
---
 build.xml                                                  |    1 -
 .../descriptor/impl/DirectoryKeyCertificateImpl.java       |   12 +++++++++---
 .../descriptor/impl/ExtraInfoDescriptorImpl.java           |   12 +++++++++---
 .../torproject/descriptor/impl/MicrodescriptorImpl.java    |   12 +++++++++---
 src/org/torproject/descriptor/impl/ParseHelper.java        |   12 +++++++-----
 src/org/torproject/descriptor/impl/RelayDirectoryImpl.java |   12 +++++++++---
 .../descriptor/impl/RelayNetworkStatusConsensusImpl.java   |   12 +++++++++---
 .../torproject/descriptor/impl/RelayNetworkStatusImpl.java |   12 +++++++++---
 .../torproject/descriptor/impl/ServerDescriptorImpl.java   |   12 +++++++++---
 9 files changed, 70 insertions(+), 27 deletions(-)

diff --git a/build.xml b/build.xml
index 35a1694..433a21a 100644
--- a/build.xml
+++ b/build.xml
@@ -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>
diff --git a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
index 3d1f797..151c384 100644
--- a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
@@ -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 "
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index 25847c4..ba7b6b6 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -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 "
diff --git a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index 7d47df0..3d83923 100644
--- a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -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 "
diff --git a/src/org/torproject/descriptor/impl/ParseHelper.java b/src/org/torproject/descriptor/impl/ParseHelper.java
index 09534c7..761a93d 100644
--- a/src/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/org/torproject/descriptor/impl/ParseHelper.java
@@ -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();
   }
 
diff --git a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
index 294faea..d88997e 100644
--- a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
@@ -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 "
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
index da75cf2..849124e 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
@@ -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 "
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
index 31e37db..06cca61 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
@@ -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 "
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index c070cc1..6070ef4 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -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 "

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits