aboutsummaryrefslogtreecommitdiffstats
path: root/sshlib/src/test
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2015-12-25 20:16:23 -0600
committerKenny Root <kenny@the-b.org>2015-12-25 20:30:55 -0600
commit1bd5343e71b7ebd09aabaebba282227a7786e5ba (patch)
tree19abd9c56bcf658286b1db7739c760627c93dd2e /sshlib/src/test
parent39aef25501455b50fff7e0cb3ddf5399ab4bfc29 (diff)
downloadsshlib-1bd5343e71b7ebd09aabaebba282227a7786e5ba.tar.gz
sshlib-1bd5343e71b7ebd09aabaebba282227a7786e5ba.tar.bz2
sshlib-1bd5343e71b7ebd09aabaebba282227a7786e5ba.zip
Add length check with test
Diffstat (limited to 'sshlib/src/test')
-rw-r--r--sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java b/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java
new file mode 100644
index 0000000..3eaec20
--- /dev/null
+++ b/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java
@@ -0,0 +1,67 @@
+package com.trilead.ssh2.crypto;
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+
+/**
+ * Created by kenny on 12/25/15.
+ */
+public class SimpleDERReaderTest {
+ @Test
+ public void readLength_Extended_OverlyLongLength() throws Exception {
+ byte[] vector = new byte[] {
+ (byte) 0x85, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals(-1, reader.readLength());
+ }
+
+ @Test
+ public void readLength_Extended_TooLongForInt() throws Exception {
+ byte[] vector = new byte[] {
+ (byte) 0x84, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals(-1, reader.readLength());
+ }
+
+ @Test
+ public void readLength_Extended_Zero() throws Exception {
+ byte[] vector = new byte[] {
+ (byte) 0x80, (byte) 0x01
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals(-1, reader.readLength());
+ }
+
+ @Test
+ public void readLength_Extended_Valid() throws Exception {
+ byte[] vector = new byte[] {
+ (byte) 0x82, (byte) 0x05, (byte) 0xFF
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals(0x5FF, reader.readLength());
+ }
+
+ @Test
+ public void readLength_Short_Zero() throws Exception {
+ byte[] vector = new byte[] {
+ (byte) 0x00
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals(0, reader.readLength());
+ }
+
+ @Test
+ public void readLength_Short_Regular() throws Exception {
+ byte[] vector = new byte[] {
+ (byte) 0x09
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals(9, reader.readLength());
+ }
+} \ No newline at end of file