From f82da34e38d4cbc0cfa6942ed930bbc22a46e503 Mon Sep 17 00:00:00 2001 From: Marcela Melara Date: Sun, 14 Aug 2016 15:54:33 -0400 Subject: [PATCH] Deprecated refactored ClientUtils functions --- .../org/coniks/coniks_server/ServerUtils.java | 16 ++++++------ coniks_test_client/pom.xml | 7 +++++ .../coniks_test_client/ClientLogger.java | 7 +++-- .../coniks_test_client/ClientUtils.java | 26 ++++++++++++++++++- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/coniks_server/src/main/java/org/coniks/coniks_server/ServerUtils.java b/coniks_server/src/main/java/org/coniks/coniks_server/ServerUtils.java index d04435e..c7d9509 100644 --- a/coniks_server/src/main/java/org/coniks/coniks_server/ServerUtils.java +++ b/coniks_server/src/main/java/org/coniks/coniks_server/ServerUtils.java @@ -85,14 +85,14 @@ public class ServerUtils{ /** The maximum number of bytes logged per log file. * - *@deprecated Moved to {@link org.coniks.util.Util}. + *@deprecated Moved to {@link org.coniks.util.Convert}. */ @Deprecated public static final int MAX_BYTES_LOGGED_PER_FILE = (1 << 15); /** The maximum number of log files per log. * - *@deprecated Moved to {@link org.coniks.util.Util}. + *@deprecated Moved to {@link org.coniks.util.Convert}. */ @Deprecated public static final int MAX_NUM_LOG_FILES = 5; @@ -106,7 +106,7 @@ public class ServerUtils{ *@param isErr indicates whether this is an error message *@param msg the status message to print * - *@deprecated Moved to {@link org.coniks.util.Util}. + *@deprecated Moved to {@link org.coniks.util.Convert}. */ @Deprecated public static void printStatusMsg (boolean isErr, String msg) { @@ -179,7 +179,7 @@ public static byte[] hashChildren(byte[] left, byte[] right){ * of its hexadecimal representation. * *@return The hex representation of {@code bytes} as a String. - *@deprecated Moved to {@link org.coniks.util.Util}. + *@deprecated Moved to {@link org.coniks.util.Convert}. */ @Deprecated public static String bytesToHex(byte[] bytes) { @@ -194,7 +194,7 @@ public static String bytesToHex(byte[] bytes) { /** Converts a UTF-8 String {@code str} to an array of bytes. * - *@deprecated Moved to {@link org.coniks.util.Util}. + *@deprecated Moved to {@link org.coniks.util.Convert}. */ @Deprecated public static byte[] strToBytes (String str) { @@ -216,7 +216,7 @@ public static byte[] unameToIndex (String uname){ /** Converts a long {@code val} into an array of bytes. * *@return The {@code byte[]} representation of the long value. - *@deprecated Moved to {@link org.coniks.util.Util}. + *@deprecated Moved to {@link org.coniks.util.Convert}. */ @Deprecated public static byte[] longToBytes(long val) { @@ -234,7 +234,7 @@ public static byte[] longToBytes(long val) { * at offset {@code offset}, and determines whether it is 1 or 0. * *@return true if the nth bit is 1, false otherwise. - *@deprecated Moved to {@link org.coniks.util.Util}. + *@deprecated Moved to {@link org.coniks.util.Convert}. */ @Deprecated public static boolean getNthBit(byte[] arr, int offset){ @@ -248,7 +248,7 @@ public static boolean getNthBit(byte[] arr, int offset){ * *@return the first 16 bits of {@code arr} or all zeros if the length * of the array is less than 2 bytes. - *@deprecated Moved to {@link org.coniks.util.Util}. + *@deprecated Moved to {@link org.coniks.util.Convert}. */ @Deprecated public static byte[] getPrefixBytes(byte[] arr){ diff --git a/coniks_test_client/pom.xml b/coniks_test_client/pom.xml index 2547579..1092e3c 100644 --- a/coniks_test_client/pom.xml +++ b/coniks_test_client/pom.xml @@ -33,6 +33,13 @@ compile + + org.coniks.util + coniks-util + 1.3-SNAPSHOT + compile + + com.google.protobuf protobuf-java diff --git a/coniks_test_client/src/main/java/org/coniks/coniks_test_client/ClientLogger.java b/coniks_test_client/src/main/java/org/coniks/coniks_test_client/ClientLogger.java index b0de7a5..c9e038e 100644 --- a/coniks_test_client/src/main/java/org/coniks/coniks_test_client/ClientLogger.java +++ b/coniks_test_client/src/main/java/org/coniks/coniks_test_client/ClientLogger.java @@ -39,6 +39,9 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, import java.util.logging.Level; import java.io.IOException; +// coniks-java imports +import org.coniks.util.Convert; + /** Implements the logger used for a CONIKS client. * *@author Marcela S. Melara (melara@cs.princeton.edu) @@ -61,8 +64,8 @@ public static void setup (String clientLog) { try { FileHandler handler = new FileHandler(clientLog, - ClientUtils.MAX_BYTES_LOGGED_PER_FILE, - ClientUtils.MAX_NUM_LOG_FILES, true); + Convert.MAX_BYTES_LOGGED_PER_FILE, + Convert.MAX_NUM_LOG_FILES, true); // create a TXT formatter SimpleFormatter fmt = new SimpleFormatter(); diff --git a/coniks_test_client/src/main/java/org/coniks/coniks_test_client/ClientUtils.java b/coniks_test_client/src/main/java/org/coniks/coniks_test_client/ClientUtils.java index a91ad40..038fe50 100644 --- a/coniks_test_client/src/main/java/org/coniks/coniks_test_client/ClientUtils.java +++ b/coniks_test_client/src/main/java/org/coniks/coniks_test_client/ClientUtils.java @@ -88,11 +88,17 @@ public class ClientUtils{ public static final int SIG_SIZE_BYTES = 256; /** The maximum number of bytes logged per log file. + * + *@deprecated Moved to {@link org.coniks.util.Convert}. */ + @Deprecated public static final int MAX_BYTES_LOGGED_PER_FILE = (1 << 15); /** The maximum number of log files per log. + * + *@deprecated Moved to {@link org.coniks.util.Convert}. */ + @Deprecated public static final int MAX_NUM_LOG_FILES = 5; /** Indicates a generic internal client error. @@ -100,6 +106,7 @@ public class ClientUtils{ // TODO: is this where it makes most sense to put this? public static final int INTERNAL_CLIENT_ERR = 1; + @Deprecated private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); /** Generates the cryptographic hash of {@code input}. @@ -158,12 +165,15 @@ public static byte[] hashChildren(byte[] left, byte[] right){ } + // from Stackoverflow 9655181 /** Converts a {@code byte[]} into a String * of its hexadecimal representation. * *@return The hex representation of {@code bytes} as a String. + * + *@deprecated Moved to {@link org.coniks.util.Convert}. */ - // from Stackoverflow 9655181 + @Deprecated public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for ( int j = 0; j < bytes.length; j++ ) { @@ -175,7 +185,10 @@ public static String bytesToHex(byte[] bytes) { } /** Converts a UTF-8 String {@code str} to an array of bytes. + * + *@deprecated Moved to {@link org.coniks.util.Convert}. */ + @Deprecated public static byte[] strToBytes (String str) { return str.getBytes(Charset.forName("UTF-8")); } @@ -195,7 +208,10 @@ public static byte[] unameToIndex (String username){ /** Converts a long {@code val} into an array of bytes. * *@return The {@code byte[]} representation of the long value. + * + *@deprecated Moved to {@link org.coniks.util.Convert}. */ + @Deprecated public static byte[] longToBytes(long val) { byte[] byteArr = new byte[8]; @@ -211,7 +227,10 @@ public static byte[] longToBytes(long val) { * at offset {@code offset}, and determines whether it is 1 or 0. * *@return true if the nth bit is 1, false otherwise. + * + *@deprecated Moved to {@link org.coniks.util.Convert}. */ + @Deprecated public static boolean getNthBit(byte[] arr, int offset){ int arrayOffset = offset / 8; int bitOfByte = offset % 8; @@ -223,7 +242,10 @@ public static boolean getNthBit(byte[] arr, int offset){ * *@return the first 16 bits of {@code arr} or all zeros if the length * of the array is less than 2 bytes. + * + *@deprecated Moved to {@link org.coniks.util.Convert}. */ + @Deprecated public static byte[] getPrefixBytes(byte[] arr){ byte[] out = new byte[2]; @@ -242,7 +264,9 @@ public static byte[] getPrefixBytes(byte[] arr){ /** Compares two byte buffers for byte-by-byte equality. * *@return true if the buffers are identical, false otherwise. + *@deprecated Use {@link java.util.Arrays#equals(byte[], byte[])} */ + @Deprecated public static boolean compareByteBuffers(byte[] buf1, byte[] buf2){ if (buf1.length != buf2.length) { return false;