@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 }))); }
@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))); }
str.dispose(); try { decryptToBytes(str); fail("expected exception"); } catch (IllegalStateException e) {