int padlen = Utils.decodeByte(in) & 0xff;
int msgType = Utils.decodeByte(in);
Class<? extends SSHMessage> klass
= getMessageClass(msgType, namespace);
if (klass == null) {
throw new SSHException("Unsupported message type: " + msgType);
}
SSHMessage msg;
try {
msg = klass.newInstance();
PayloadInputStream pin = new PayloadInputStream(in, plen - padlen - 2);
msg.decode(pin);
pin.flush();
} catch (IllegalAccessException iae) {
throw new SSHException("Unable to create message", iae);
} catch (InstantiationException ie) {
throw new SSHException("Unable to create message", ie);
}
Utils.decodeBytes(in, padlen);
if (!in.checkMac()) {
GlieseLogger.LOGGER.error("Invalid MAC on message: " + msg);
try {
writeMessage(new DisconnectMessage(
DisconnectMessage.MAC_ERROR,
"Bad MAC on input", ""));
} catch (SSHException se) {
// ignore exception
}
throw new SSHException("Bad MAC on input");
}
in.notifyAll();
return msg;
}
}