aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cz/crcs/ectester/applet/ECTesterApplet.java1
-rw-r--r--src/cz/crcs/ectester/common/output/BaseTextTestWriter.java15
-rw-r--r--src/cz/crcs/ectester/common/output/TestWriter.java8
-rw-r--r--src/cz/crcs/ectester/common/test/TestSuite.java2
-rw-r--r--src/cz/crcs/ectester/common/util/ByteUtil.java30
-rw-r--r--src/cz/crcs/ectester/reader/ECTesterReader.java8
6 files changed, 57 insertions, 7 deletions
diff --git a/src/cz/crcs/ectester/applet/ECTesterApplet.java b/src/cz/crcs/ectester/applet/ECTesterApplet.java
index 9689a51..5c87105 100644
--- a/src/cz/crcs/ectester/applet/ECTesterApplet.java
+++ b/src/cz/crcs/ectester/applet/ECTesterApplet.java
@@ -582,7 +582,6 @@ public class ECTesterApplet extends Applet implements ExtendedLength {
length += keyGenerator.exportParameters(keyPair, EC_Consts.KEY_PUBLIC, params, outBuffer, outOffset);
sw = keyGenerator.getSW();
}
- //TODO unify this, now that param key == the passed on param.
if ((key & EC_Consts.KEY_PRIVATE) != 0 && sw == ISO7816.SW_NO_ERROR) {
//export params from private
length += keyGenerator.exportParameters(keyPair, EC_Consts.KEY_PRIVATE, params, outBuffer, (short) (outOffset + length));
diff --git a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java
index f29d28e..4315201 100644
--- a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java
+++ b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java
@@ -5,6 +5,11 @@ import cz.crcs.ectester.common.test.*;
import java.io.PrintStream;
/**
+ * An absctract basis of a TextTestWriter, which outputs in a human readable format, into console.
+ * Requires the implementation of:
+ * <code>String testableString(Testable t)</code>
+ * <code>String deviceString(TestSuite t)</code>
+ *
* @author Jan Jancar johny@neuromancer.sk
*/
public abstract class BaseTextTestWriter implements TestWriter {
@@ -23,8 +28,18 @@ public abstract class BaseTextTestWriter implements TestWriter {
output.print(deviceString(suite));
}
+ /**
+ *
+ * @param t
+ * @return
+ */
protected abstract String testableString(Testable t);
+ /**
+ *
+ * @param suite
+ * @return
+ */
protected abstract String deviceString(TestSuite suite);
private String testString(Test t, String prefix) {
diff --git a/src/cz/crcs/ectester/common/output/TestWriter.java b/src/cz/crcs/ectester/common/output/TestWriter.java
index 5fa7f67..7de23a5 100644
--- a/src/cz/crcs/ectester/common/output/TestWriter.java
+++ b/src/cz/crcs/ectester/common/output/TestWriter.java
@@ -8,7 +8,13 @@ import cz.crcs.ectester.common.test.TestSuite;
*/
public interface TestWriter {
/**
- * @param suite
+ * Begin writing the <code>TestSuite suite</code>.
+ * This should reset all the internal state of the writer
+ * and prepare it to output tests from <code>suite</code>.
+ * It may also write any header part of the output of the
+ * writer but doesn't have to.
+ *
+ * @param suite The <code>TestSuite</code> to start writing.
*/
void begin(TestSuite suite);
diff --git a/src/cz/crcs/ectester/common/test/TestSuite.java b/src/cz/crcs/ectester/common/test/TestSuite.java
index ca1b199..7883633 100644
--- a/src/cz/crcs/ectester/common/test/TestSuite.java
+++ b/src/cz/crcs/ectester/common/test/TestSuite.java
@@ -18,7 +18,7 @@ public abstract class TestSuite {
}
/**
- *
+ * Run the <code>TestSuite</code>.
*/
public void run() {
writer.begin(this);
diff --git a/src/cz/crcs/ectester/common/util/ByteUtil.java b/src/cz/crcs/ectester/common/util/ByteUtil.java
index ad9f1bf..0de8dc7 100644
--- a/src/cz/crcs/ectester/common/util/ByteUtil.java
+++ b/src/cz/crcs/ectester/common/util/ByteUtil.java
@@ -7,15 +7,27 @@ package cz.crcs.ectester.common.util;
* @author Jan Jancar johny@neuromancer.sk
*/
public class ByteUtil {
+
+ /**
+ * Gen a short from a byte array at <code>offset</code>, big-endian.
+ * @return the short value
+ */
public static short getShort(byte[] array, int offset) {
return (short) (((array[offset] & 0xFF) << 8) | (array[offset + 1] & 0xFF));
}
+ /**
+ * Set a short in a byte array at <code>offset</code>, big-endian.
+ */
public static void setShort(byte[] array, int offset, short value) {
array[offset + 1] = (byte) (value & 0xFF);
array[offset] = (byte) ((value >> 8) & 0xFF);
}
+ /**
+ * Compare two byte arrays upto <code>length</code> and get first difference.
+ * @return the position of the first difference in the two byte arrays, or <code>length</code> if they are equal.
+ */
public static int diffBytes(byte[] one, int oneOffset, byte[] other, int otherOffset, int length) {
for (int i = 0; i < length; ++i) {
byte a = one[i + oneOffset];
@@ -27,10 +39,17 @@ public class ByteUtil {
return length;
}
+ /**
+ * Compare two byte arrays, upto <code>length</code>.
+ * @return whether the arrays are equal upto <code>length</code>
+ */
public static boolean compareBytes(byte[] one, int oneOffset, byte[] other, int otherOffset, int length) {
return diffBytes(one, oneOffset, other, otherOffset, length) == length;
}
+ /**
+ * Test if the byte array has all values equal to <code>value</code>.
+ */
public static boolean allValue(byte[] array, byte value) {
for (byte a : array) {
if (a != value)
@@ -56,10 +75,21 @@ public class ByteUtil {
return result;
}
+ /**
+ * Parse a hex string into a byte array, big-endian.
+ * @param hex The String to parse.
+ * @return the byte array from the hex string.
+ */
public static byte[] hexToBytes(String hex) {
return hexToBytes(hex, true);
}
+ /**
+ * Parse a hex string into a byte-array, specify endianity.
+ * @param hex The String to parse.
+ * @param bigEndian Whether to parse as big-endian.
+ * @return the byte array from the hex string.
+ */
public static byte[] hexToBytes(String hex, boolean bigEndian) {
hex = hex.replace(" ", "");
int len = hex.length();
diff --git a/src/cz/crcs/ectester/reader/ECTesterReader.java b/src/cz/crcs/ectester/reader/ECTesterReader.java
index ef2d235..9c80bd2 100644
--- a/src/cz/crcs/ectester/reader/ECTesterReader.java
+++ b/src/cz/crcs/ectester/reader/ECTesterReader.java
@@ -726,7 +726,7 @@ public class ECTesterReader {
System.err.println("You have to specify an output file for curve parameter export.");
return false;
}
- if (all) {
+ if (all || bits == 0) {
System.err.println("You have to specify curve bit-size with -b");
return false;
}
@@ -743,7 +743,7 @@ public class ECTesterReader {
System.err.println("You have to specify an output file for the key generation process.");
return false;
}
- if (all) {
+ if (all || bits == 0) {
System.err.println("You have to specify curve bit-size with -b");
return false;
}
@@ -770,7 +770,7 @@ public class ECTesterReader {
System.err.print("Need to specify field with -fp or -f2m. (not both)");
return false;
}
- if (all) {
+ if (all || bits == 0) {
System.err.println("You have to specify curve bit-size with -b");
return false;
}
@@ -787,7 +787,7 @@ public class ECTesterReader {
System.err.print("Need to specify field with -fp or -f2m. (but not both)");
return false;
}
- if (all) {
+ if (all || bits == 0) {
System.err.println("You have to specify curve bit-size with -b");
return false;
}