@Test public void testEquals() { GuardedByteArray bytes1 = new GuardedByteArray(); GuardedByteArray bytes2 = new GuardedByteArray(); assertEquals(bytes1, bytes2); bytes2.appendByte((byte) 0x03); assertFalse(bytes1.equals(bytes2)); bytes1.appendByte((byte) 0x03); assertEquals(bytes1, bytes2); }
@Test public void testReadOnly() { GuardedByteArray bytes = new GuardedByteArray(new byte[] { 0x00, 0x01, 0x02 }); assertFalse(bytes.isReadOnly()); bytes.makeReadOnly(); assertTrue(bytes.isReadOnly()); assertTrue(Arrays.equals(new byte[] { 0x00, 0x01, 0x02 }, decryptToBytes(bytes))); try { bytes.appendByte((byte) 0x03); fail("expected exception"); } catch (IllegalStateException e) { /* ignore */ } bytes = bytes.copy(); assertTrue(Arrays.equals(new byte[] { 0x00, 0x01, 0x02 }, decryptToBytes(bytes))); bytes.appendByte((byte) 0x03); assertTrue(Arrays.equals(new byte[] { 0x00, 0x01, 0x02, 0x03 }, decryptToBytes(bytes))); }
@Test public void testBasics() { GuardedByteArray bytes = new GuardedByteArray(new byte[] { 0x00, 0x01, 0x02 }); assertTrue(Arrays.equals(decryptToBytes(bytes), new byte[] { 0x00, 0x01, 0x02 })); assertTrue(Arrays.equals(new byte[] { 0x00, 0x01, 0x02 }, decryptToBytes(bytes))); bytes.appendByte((byte) 0x03); assertTrue(Arrays.equals(new byte[] { 0x00, 0x01, 0x02, 0x03 }, decryptToBytes(bytes))); assertFalse(bytes.verifyBase64SHA1Hash( SecurityUtil.computeBase64SHA1Hash(new byte[] { 0x00, 0x01, 0x02 }))); assertTrue(bytes.verifyBase64SHA1Hash( SecurityUtil.computeBase64SHA1Hash(new byte[] { 0x00, 0x01, 0x02, 0x03 }))); }
str.appendByte((byte) 0x03); fail("expected exception"); } catch (IllegalStateException e) {