diff options
| author | J08nY | 2017-04-19 01:10:17 +0200 |
|---|---|---|
| committer | J08nY | 2017-04-19 01:10:17 +0200 |
| commit | a7eef06134bef0861e43261640d61153ebb2a6e5 (patch) | |
| tree | 2ef308843b4e8b1770be6681c15b98dcd78d40ff /src/cz/crcs/ectester/reader/ec/EC_Data.java | |
| parent | f4a66768ed6dfcfd7156ad0c8c364cdbf6e45e9c (diff) | |
| download | ECTester-a7eef06134bef0861e43261640d61153ebb2a6e5.tar.gz ECTester-a7eef06134bef0861e43261640d61153ebb2a6e5.tar.zst ECTester-a7eef06134bef0861e43261640d61153ebb2a6e5.zip | |
Refactor testing, add Config class, make EC_Data read bytes
- The ECTester.Config class now stores and reads all CLI options
- Testing with the -t / --test option was partially refactored
into:
- Test:
Encapsulates one Command and Response pair with expected result,
a real result and a callback to dynamically assign result
- TestSuite:
Encapsulates a bunch of tests, represents a whole category of
tests either that can be run on any curve or only on some.
Diffstat (limited to 'src/cz/crcs/ectester/reader/ec/EC_Data.java')
| -rw-r--r-- | src/cz/crcs/ectester/reader/ec/EC_Data.java | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/cz/crcs/ectester/reader/ec/EC_Data.java b/src/cz/crcs/ectester/reader/ec/EC_Data.java index c55b99d..49b5316 100644 --- a/src/cz/crcs/ectester/reader/ec/EC_Data.java +++ b/src/cz/crcs/ectester/reader/ec/EC_Data.java @@ -13,11 +13,12 @@ import java.util.regex.Pattern; * @author Jan Jancar johny@neuromancer.sk */ public class EC_Data { - private static final Pattern hex = Pattern.compile("(0x|0X)?[a-fA-F\\d]+"); - + String id; int count; byte[][] data; + private static final Pattern HEX = Pattern.compile("(0x|0X)?[a-fA-F\\d]+"); + EC_Data() { } @@ -31,6 +32,20 @@ public class EC_Data { this.data = data; } + EC_Data(String id, int count) { + this(count); + this.id = id; + } + + EC_Data(String id, byte[][] data) { + this(data); + this.id = id; + } + + public String getId() { + return id; + } + public int getCount() { return count; } @@ -117,16 +132,29 @@ public class EC_Data { return false; } for (String param : data) { - if (!hex.matcher(param).matches()) { + if (!HEX.matcher(param).matches()) { return false; } } return readHex(data.toArray(new String[data.size()])); } - public boolean readBytes(byte[] data) { - //TODO - return false; + public boolean readBytes(byte[] bytes) { + int offset = 0; + for (int i = 0; i < count; i++) { + if (bytes.length - offset < 2) { + return false; + } + short paramLength = Util.getShort(bytes, offset); + offset += 2; + if (bytes.length < offset + paramLength) { + return false; + } + data[i] = new byte[paramLength]; + System.arraycopy(bytes, offset, data[i], 0, paramLength); + offset += paramLength; + } + return true; } public void writeCSV(OutputStream out) throws IOException { |
