diff options
author | Kenny Root <kenny@the-b.org> | 2015-12-25 20:41:18 -0600 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2015-12-25 22:57:57 -0600 |
commit | d60c23560bd0464b2f8862f43711781eb45eac49 (patch) | |
tree | 273b11a3a25aad3bc876db987eb035877ee02b38 /sshlib | |
parent | 1bd5343e71b7ebd09aabaebba282227a7786e5ba (diff) | |
download | sshlib-d60c23560bd0464b2f8862f43711781eb45eac49.tar.gz sshlib-d60c23560bd0464b2f8862f43711781eb45eac49.tar.bz2 sshlib-d60c23560bd0464b2f8862f43711781eb45eac49.zip |
Add tests for readInt
Diffstat (limited to 'sshlib')
-rw-r--r-- | sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java | 48 |
1 files changed, 48 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 index 3eaec20..cabadce 100644 --- a/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java +++ b/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java @@ -3,6 +3,7 @@ package com.trilead.ssh2.crypto; import org.junit.Test; import java.io.IOException; +import java.math.BigInteger; import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; @@ -64,4 +65,51 @@ public class SimpleDERReaderTest { SimpleDERReader reader = new SimpleDERReader(vector); assertEquals(9, reader.readLength()); } + + @Test + public void readInt_MaxInt() throws Exception { + byte[] vector = new byte[] { + (byte) 0x02, (byte) 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + }; + SimpleDERReader reader = new SimpleDERReader(vector); + assertEquals(BigInteger.valueOf(0xFFFFFFFF), reader.readInt()); + } + + @Test + public void readInt_NotReallyInteger() throws Exception { + byte[] vector = new byte[] { + (byte) 0x01, (byte) 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + }; + SimpleDERReader reader = new SimpleDERReader(vector); + try { + reader.readInt(); + } catch (IOException expected) { + assertThat(expected.getMessage(), containsString("Expected DER Integer")); + } + } + + @Test + public void readInt_InvalidLength() throws Exception { + byte[] vector = new byte[] { + (byte) 0x02, (byte) 0x80, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + }; + SimpleDERReader reader = new SimpleDERReader(vector); + try { + reader.readInt(); + } catch (IOException expected) { + assertThat(expected.getMessage(), containsString("Illegal len")); + } + } + + @Test + public void readInt_ShortArray() throws Exception { + byte[] vector = new byte[] { + (byte) 0x02, (byte) 0x02, (byte) 0xFF + }; + SimpleDERReader reader = new SimpleDERReader(vector); + try { + reader.readInt(); + } catch (IOException expected) { + } + } }
\ No newline at end of file |