summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'test/com/isode/stroke/stringcodecs')
-rw-r--r--test/com/isode/stroke/stringcodecs/HMACSHA1Test.java34
-rw-r--r--test/com/isode/stroke/stringcodecs/SHA1Test.java44
2 files changed, 78 insertions, 0 deletions
diff --git a/test/com/isode/stroke/stringcodecs/HMACSHA1Test.java b/test/com/isode/stroke/stringcodecs/HMACSHA1Test.java
new file mode 100644
index 0000000..dedcd7c
--- /dev/null
+++ b/test/com/isode/stroke/stringcodecs/HMACSHA1Test.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010, Isode Limited, London, England.
+ * All rights reserved.
+ */
+/*
+ * Copyright (c) 2010, Remko Tron?on.
+ * All rights reserved.
+ */
+
+package com.isode.stroke.stringcodecs;
+
+import com.isode.stroke.base.ByteArray;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class HMACSHA1Test {
+
+ private ByteArray cast(int[] source) {
+ byte[] result = new byte[source.length];
+ for (int i = 0; i < source.length; i++) {
+ result[i] = (byte)source[i];
+ }
+ return new ByteArray(result);
+ }
+
+ @Test
+ public void testGetResult() {
+ ByteArray result = HMACSHA1.getResult(new ByteArray("foo"), new ByteArray("foobar"));
+ assertEquals(cast(new int[]{0xa4, 0xee, 0xba, 0x8e, 0x63, 0x3d, 0x77, 0x88, 0x69, 0xf5, 0x68, 0xd0, 0x5a, 0x1b, 0x3d, 0xc7, 0x2b, 0xfd, 0x4, 0xdd}), result);
+ }
+}
diff --git a/test/com/isode/stroke/stringcodecs/SHA1Test.java b/test/com/isode/stroke/stringcodecs/SHA1Test.java
new file mode 100644
index 0000000..c8c8a9b
--- /dev/null
+++ b/test/com/isode/stroke/stringcodecs/SHA1Test.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2010, Isode Limited, London, England.
+ * All rights reserved.
+ */
+/*
+ * Copyright (c) 2010, Remko Tron?on.
+ * All rights reserved.
+ */
+package com.isode.stroke.stringcodecs;
+
+import com.isode.stroke.base.ByteArray;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class SHA1Test {
+
+ public SHA1Test() {
+ }
+
+ @Test
+ public void testGetHash() {
+ ByteArray result = new ByteArray(SHA1.getHash(new ByteArray("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<")));
+ ByteArray target = new ByteArray(new byte[]{(byte) 0x42, (byte) 0x06, (byte) 0xb2, (byte) 0x3c, (byte) 0xa6, (byte) 0xb0, (byte) 0xa6, (byte) 0x43, (byte) 0xd2, (byte) 0x0d, (byte) 0x89, (byte) 0xb0, (byte) 0x4f, (byte) 0xf5, (byte) 0x8c, (byte) 0xf7, (byte) 0x8b, (byte) 0x80, (byte) 0x96, (byte) 0xed});
+ assertEquals(target, result);
+ }
+
+ @Test
+ public void testGetHash_Twice() {
+ ByteArray input = new ByteArray("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<");
+ SHA1.getHash(input);
+ ByteArray result = SHA1.getHash(input);
+
+ assertEquals(new ByteArray(new byte[]{(byte) 0x42, (byte) 0x06, (byte) 0xb2, (byte) 0x3c, (byte) 0xa6, (byte) 0xb0, (byte) 0xa6, (byte) 0x43, (byte) 0xd2, (byte) 0x0d, (byte) 0x89, (byte) 0xb0, (byte) 0x4f, (byte) 0xf5, (byte) 0x8c, (byte) 0xf7, (byte) 0x8b, (byte) 0x80, (byte) 0x96, (byte) 0xed}), result);
+ }
+
+ @Test
+ public void testGetHash_NoData() {
+ ByteArray result = SHA1.getHash(new ByteArray());
+
+ assertEquals(new ByteArray(new byte[]{(byte) 0xda, (byte) 0x39, (byte) 0xa3, (byte) 0xee, (byte) 0x5e, (byte) 0x6b, (byte) 0x4b, (byte) 0x0d, (byte) 0x32, (byte) 0x55, (byte) 0xbf, (byte) 0xef, (byte) 0x95, (byte) 0x60, (byte) 0x18, (byte) 0x90, (byte) 0xaf, (byte) 0xd8, (byte) 0x07, (byte) 0x09}), result);
+ }
+}