diff options
Diffstat (limited to 'core/src/main/j2me/org/spongycastle/util')
5 files changed, 131 insertions, 0 deletions
diff --git a/core/src/main/j2me/org/spongycastle/util/Integers.java b/core/src/main/j2me/org/spongycastle/util/Integers.java new file mode 100644 index 00000000..bf6b5e34 --- /dev/null +++ b/core/src/main/j2me/org/spongycastle/util/Integers.java @@ -0,0 +1,19 @@ +package org.spongycastle.util; + +public class Integers +{ + public static int rotateLeft(int i, int distance) + { + return (i << distance) ^ (i >>> -distance); + } + + public static int rotateRight(int i, int distance) + { + return (i >>> distance) ^ (i << -distance); + } + + public static Integer valueOf(int value) + { + return new Integer(value); + } +} diff --git a/core/src/main/j2me/org/spongycastle/util/Selector.java b/core/src/main/j2me/org/spongycastle/util/Selector.java new file mode 100644 index 00000000..a72cdaa2 --- /dev/null +++ b/core/src/main/j2me/org/spongycastle/util/Selector.java @@ -0,0 +1,8 @@ +package org.spongycastle.util; + +public interface Selector +{ + boolean match(Object obj); + + Object clone(); +} diff --git a/core/src/main/j2me/org/spongycastle/util/Shorts.java b/core/src/main/j2me/org/spongycastle/util/Shorts.java new file mode 100644 index 00000000..66a992f7 --- /dev/null +++ b/core/src/main/j2me/org/spongycastle/util/Shorts.java @@ -0,0 +1,9 @@ +package org.spongycastle.util; + +public class Shorts +{ + public static Short valueOf(short value) + { + return new Short(value); + } +} diff --git a/core/src/main/j2me/org/spongycastle/util/Times.java b/core/src/main/j2me/org/spongycastle/util/Times.java new file mode 100644 index 00000000..f88b5395 --- /dev/null +++ b/core/src/main/j2me/org/spongycastle/util/Times.java @@ -0,0 +1,11 @@ +package org.spongycastle.util; + +public final class Times +{ + private static long NANOS_PER_MILLI = 1000000L; + + public static long nanoTime() + { + return NANOS_PER_MILLI * System.currentTimeMillis(); + } +} diff --git a/core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java b/core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java new file mode 100644 index 00000000..a61e3bdd --- /dev/null +++ b/core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java @@ -0,0 +1,84 @@ +package org.spongycastle.util.test; + +import java.io.PrintStream; + +import org.spongycastle.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(); + } + } + + public abstract void performTest() + throws Exception; +} |