summaryrefslogtreecommitdiffstats
path: root/bcprov/src/main/java/org/bouncycastle/util/test
diff options
context:
space:
mode:
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/util/test')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/FixedSecureRandom.java135
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/NumberParsing.java34
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/SimpleTest.java84
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/SimpleTestResult.java80
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/Test.java8
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/TestFailedException.java18
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/TestResult.java10
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/UncloseableOutputStream.java23
-rw-r--r--bcprov/src/main/java/org/bouncycastle/util/test/package.html5
9 files changed, 0 insertions, 397 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/FixedSecureRandom.java b/bcprov/src/main/java/org/bouncycastle/util/test/FixedSecureRandom.java
deleted file mode 100644
index 49bd730..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/FixedSecureRandom.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package org.bouncycastle.util.test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.security.SecureRandom;
-
-public class FixedSecureRandom
- extends SecureRandom
-{
- private byte[] _data;
-
- private int _index;
- private int _intPad;
-
- public FixedSecureRandom(byte[] value)
- {
- this(false, new byte[][] { value });
- }
-
- public FixedSecureRandom(
- byte[][] values)
- {
- this(false, values);
- }
-
- /**
- * Pad the data on integer boundaries. This is necessary for the classpath project's BigInteger
- * implementation.
- */
- public FixedSecureRandom(
- boolean intPad,
- byte[] value)
- {
- this(intPad, new byte[][] { value });
- }
-
- /**
- * Pad the data on integer boundaries. This is necessary for the classpath project's BigInteger
- * implementation.
- */
- public FixedSecureRandom(
- boolean intPad,
- byte[][] values)
- {
- ByteArrayOutputStream bOut = new ByteArrayOutputStream();
-
- for (int i = 0; i != values.length; i++)
- {
- try
- {
- bOut.write(values[i]);
- }
- catch (IOException e)
- {
- throw new IllegalArgumentException("can't save value array.");
- }
- }
-
- _data = bOut.toByteArray();
-
- if (intPad)
- {
- _intPad = _data.length % 4;
- }
- }
-
- public void nextBytes(byte[] bytes)
- {
- System.arraycopy(_data, _index, bytes, 0, bytes.length);
-
- _index += bytes.length;
- }
-
- //
- // classpath's implementation of SecureRandom doesn't currently go back to nextBytes
- // when next is called. We can't override next as it's a final method.
- //
- public int nextInt()
- {
- int val = 0;
-
- val |= nextValue() << 24;
- val |= nextValue() << 16;
-
- if (_intPad == 2)
- {
- _intPad--;
- }
- else
- {
- val |= nextValue() << 8;
- }
-
- if (_intPad == 1)
- {
- _intPad--;
- }
- else
- {
- val |= nextValue();
- }
-
- return val;
- }
-
- //
- // classpath's implementation of SecureRandom doesn't currently go back to nextBytes
- // when next is called. We can't override next as it's a final method.
- //
- public long nextLong()
- {
- long val = 0;
-
- val |= (long)nextValue() << 56;
- val |= (long)nextValue() << 48;
- val |= (long)nextValue() << 40;
- val |= (long)nextValue() << 32;
- val |= (long)nextValue() << 24;
- val |= (long)nextValue() << 16;
- val |= (long)nextValue() << 8;
- val |= (long)nextValue();
-
- return val;
- }
-
- public boolean isExhausted()
- {
- return _index == _data.length;
- }
-
- private int nextValue()
- {
- return _data[_index++] & 0xff;
- }
-}
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/NumberParsing.java b/bcprov/src/main/java/org/bouncycastle/util/test/NumberParsing.java
deleted file mode 100644
index a060dd8..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/NumberParsing.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.bouncycastle.util.test;
-
-/**
- * Parsing
- */
-public final class NumberParsing
-{
- private NumberParsing()
- {
- // Hide constructor
- }
-
- public static long decodeLongFromHex(String longAsString)
- {
- if ((longAsString.charAt(1) == 'x')
- || (longAsString.charAt(1) == 'X'))
- {
- return Long.parseLong(longAsString.substring(2), 16);
- }
-
- return Long.parseLong(longAsString, 16);
- }
-
- public static int decodeIntFromHex(String intAsString)
- {
- if ((intAsString.charAt(1) == 'x')
- || (intAsString.charAt(1) == 'X'))
- {
- return Integer.parseInt(intAsString.substring(2), 16);
- }
-
- return Integer.parseInt(intAsString, 16);
- }
-}
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/SimpleTest.java b/bcprov/src/main/java/org/bouncycastle/util/test/SimpleTest.java
deleted file mode 100644
index ef8ee61..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/SimpleTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.bouncycastle.util.test;
-
-import java.io.PrintStream;
-
-import org.bouncycastle.util.Arrays;
-
-public abstract class SimpleTest
- implements Test
-{
- public abstract String getName();
-
- private TestResult success()
- {
- return SimpleTestResult.successful(this, "Okay");
- }
-
- protected void fail(
- String message)
- {
- throw new TestFailedException(SimpleTestResult.failed(this, message));
- }
-
- protected void fail(
- String message,
- Throwable throwable)
- {
- throw new TestFailedException(SimpleTestResult.failed(this, message, throwable));
- }
-
- protected void fail(
- String message,
- Object expected,
- Object found)
- {
- throw new TestFailedException(SimpleTestResult.failed(this, message, expected, found));
- }
-
- protected boolean areEqual(
- byte[] a,
- byte[] b)
- {
- return Arrays.areEqual(a, b);
- }
-
- public TestResult perform()
- {
- try
- {
- performTest();
-
- return success();
- }
- catch (TestFailedException e)
- {
- return e.getResult();
- }
- catch (Exception e)
- {
- return SimpleTestResult.failed(this, "Exception: " + e, e);
- }
- }
-
- protected static void runTest(
- Test test)
- {
- runTest(test, System.out);
- }
-
- protected static void runTest(
- Test test,
- PrintStream out)
- {
- TestResult result = test.perform();
-
- out.println(result.toString());
- if (result.getException() != null)
- {
- result.getException().printStackTrace(out);
- }
- }
-
- public abstract void performTest()
- throws Exception;
-}
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/SimpleTestResult.java b/bcprov/src/main/java/org/bouncycastle/util/test/SimpleTestResult.java
deleted file mode 100644
index bd69fe8..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/SimpleTestResult.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.bouncycastle.util.test;
-
-public class SimpleTestResult implements TestResult
-{
- private static final String SEPARATOR = System.getProperty("line.separator");
-
- private boolean success;
- private String message;
- private Throwable exception;
-
- public SimpleTestResult(boolean success, String message)
- {
- this.success = success;
- this.message = message;
- }
-
- public SimpleTestResult(boolean success, String message, Throwable exception)
- {
- this.success = success;
- this.message = message;
- this.exception = exception;
- }
-
- public static TestResult successful(
- Test test,
- String message)
- {
- return new SimpleTestResult(true, test.getName() + ": " + message);
- }
-
- public static TestResult failed(
- Test test,
- String message)
- {
- return new SimpleTestResult(false, test.getName() + ": " + message);
- }
-
- public static TestResult failed(
- Test test,
- String message,
- Throwable t)
- {
- return new SimpleTestResult(false, test.getName() + ": " + message, t);
- }
-
- public static TestResult failed(
- Test test,
- String message,
- Object expected,
- Object found)
- {
- return failed(test, message + SEPARATOR + "Expected: " + expected + SEPARATOR + "Found : " + found);
- }
-
- public static String failedMessage(String algorithm, String testName, String expected,
- String actual)
- {
- StringBuffer sb = new StringBuffer(algorithm);
- sb.append(" failing ").append(testName);
- sb.append(SEPARATOR).append(" expected: ").append(expected);
- sb.append(SEPARATOR).append(" got : ").append(actual);
-
- return sb.toString();
- }
-
- public boolean isSuccessful()
- {
- return success;
- }
-
- public String toString()
- {
- return message;
- }
-
- public Throwable getException()
- {
- return exception;
- }
-}
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/Test.java b/bcprov/src/main/java/org/bouncycastle/util/test/Test.java
deleted file mode 100644
index e631cd0..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/Test.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.bouncycastle.util.test;
-
-public interface Test
-{
- String getName();
-
- TestResult perform();
-}
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/TestFailedException.java b/bcprov/src/main/java/org/bouncycastle/util/test/TestFailedException.java
deleted file mode 100644
index 21e95d3..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/TestFailedException.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.bouncycastle.util.test;
-
-public class TestFailedException
- extends RuntimeException
-{
- private TestResult _result;
-
- public TestFailedException(
- TestResult result)
- {
- _result = result;
- }
-
- public TestResult getResult()
- {
- return _result;
- }
-}
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/TestResult.java b/bcprov/src/main/java/org/bouncycastle/util/test/TestResult.java
deleted file mode 100644
index 0a1885f..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/TestResult.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.bouncycastle.util.test;
-
-public interface TestResult
-{
- public boolean isSuccessful();
-
- public Throwable getException();
-
- public String toString();
-}
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/UncloseableOutputStream.java b/bcprov/src/main/java/org/bouncycastle/util/test/UncloseableOutputStream.java
deleted file mode 100644
index 89073d7..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/UncloseableOutputStream.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.bouncycastle.util.test;
-
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class UncloseableOutputStream extends FilterOutputStream
-{
- public UncloseableOutputStream(OutputStream s)
- {
- super(s);
- }
-
- public void close()
- {
- throw new RuntimeException("close() called on UncloseableOutputStream");
- }
-
- public void write(byte[] b, int off, int len) throws IOException
- {
- out.write(b, off, len);
- }
- }
diff --git a/bcprov/src/main/java/org/bouncycastle/util/test/package.html b/bcprov/src/main/java/org/bouncycastle/util/test/package.html
deleted file mode 100644
index e723fd1..0000000
--- a/bcprov/src/main/java/org/bouncycastle/util/test/package.html
+++ /dev/null
@@ -1,5 +0,0 @@
-<html>
-<body bgcolor="#ffffff">
-Light weight test API. If you can use Junit!
-</body>
-</html>