Code with Misuse: |
class SecureMessagingWrapper {
/**
* The <code>0x87</code> tag has already been read.
*
* @param in inputstream to read from.
*/
private byte[] readDO87(DataInputStream in)
throws IOException, GeneralSecurityException {
/* Read length... */
int length = 0;
int buf = in.readUnsignedByte();
if ((buf & 0x00000080) != 0x00000080) {
/* Short form */
length = buf;
buf = in.readUnsignedByte(); /* should be 0x01... */
if (buf != 0x01) {
throw new IllegalStateException("DO'87 expected 0x01 marker "
+ Integer.toHexString(buf));
}
} else {
/* Long form */
int lengthBytesCount = buf & 0x0000007F;
for (int i = 0; i < lengthBytesCount; i++) {
length = (length << 8) | in.readUnsignedByte();
}
buf = in.readUnsignedByte(); /* should be 0x01... */
if (buf != 0x01) {
throw new IllegalStateException("DO'87 expected 0x01 marker");
}
}
length--; /* takes care of the extra 0x01 marker... */
/* Read, decrypt, unpad the data... */
byte[] ciphertext = new byte[length];
in.read(ciphertext, 0, length);
byte[] paddedData = cipher.doFinal(ciphertext);
// System.out.println("DEBUG: paddedData = " + Hex.bytesToHexString(paddedData));
byte[] data = Util.unpad(paddedData);
return data;
}
}
|