@@ -639,6 +639,8 @@ static int getPayloadLength(final HandshakePattern handshakePattern,
639639 *
640640 * @return a new byte array containing the resulting handshake message
641641 *
642+ * @throws IllegalArgumentException if the message produced for the given payload would be larger than the maximum
643+ * allowed Noise handshake message size
642644 * @throws IllegalStateException if this handshake is not currently expecting to send a handshake message to its peer
643645 *
644646 * @see #isExpectingWrite()
@@ -679,6 +681,8 @@ public byte[] writeMessage(@Nullable final byte[] payload) {
679681 *
680682 * @return the number of bytes written to {@code message}
681683 *
684+ * @throws IllegalArgumentException if the message produced for the given payload would be larger than the maximum
685+ * allowed Noise handshake message size
682686 * @throws IllegalStateException if this handshake is not currently expecting to send a handshake message to its peer
683687 * @throws ShortBufferException if {@code message} is not large enough (after its offset) to hold the handshake
684688 * message
@@ -771,6 +775,8 @@ public int writeMessage(@Nullable final byte[] payload,
771775 *
772776 * @return a new byte buffer containing the resulting handshake message
773777 *
778+ * @throws IllegalArgumentException if the message produced for the given payload would be larger than the maximum
779+ * allowed Noise handshake message size
774780 * @throws IllegalStateException if this handshake is not currently expecting to send a handshake message to its peer
775781 *
776782 * @see #isExpectingWrite()
@@ -811,6 +817,8 @@ public ByteBuffer writeMessage(@Nullable final ByteBuffer payload) {
811817 *
812818 * @return the number of bytes written to {@code message}
813819 *
820+ * @throws IllegalArgumentException if the message produced for the given payload would be larger than the maximum
821+ * allowed Noise handshake message size
814822 * @throws IllegalStateException if this handshake is not currently expecting to send a handshake message to its peer
815823 * @throws ShortBufferException if {@code message} does not have enough remaining capacity to hold the handshake
816824 * message
@@ -899,7 +907,8 @@ private void checkOutboundMessageSize(final int payloadLength) {
899907 *
900908 * @throws AEADBadTagException if the AEAD tag for any encrypted component of the given handshake message does not
901909 * match the calculated value
902- * @throws IllegalArgumentException if the given message is too short to contain the expected handshake message
910+ * @throws IllegalArgumentException if the given message is too short to contain the expected handshake message or if
911+ * the given message is larger than the maximum allowed Noise handshake message size
903912 */
904913 public byte [] readMessage (final byte [] message ) throws AEADBadTagException {
905914 checkInboundMessageSize (message .length );
@@ -934,8 +943,9 @@ public byte[] readMessage(final byte[] message) throws AEADBadTagException {
934943 * match the calculated value
935944 * @throws ShortBufferException if {@code payload} is too short (after its offset) to hold the plaintext of the
936945 * payload included in the given handshake message
937- * @throws IllegalArgumentException if the given message is too short to contain the expected handshake message
938- *
946+ * @throws IllegalArgumentException if the given message is too short to contain the expected handshake message or if
947+ * the given message is larger than the maximum allowed Noise handshake message size
948+ *
939949 * @see #getPayloadLength(int)
940950 */
941951 public int readMessage (final byte [] message ,
@@ -1013,7 +1023,8 @@ public int readMessage(final byte[] message,
10131023 *
10141024 * @throws AEADBadTagException if the AEAD tag for any encrypted component of the given handshake message does not
10151025 * match the calculated value
1016- * @throws IllegalArgumentException if the given message is too short to contain the expected handshake message
1026+ * @throws IllegalArgumentException if the given message is too short to contain the expected handshake message or if
1027+ * the given message is larger than the maximum allowed Noise handshake message size
10171028 */
10181029 public ByteBuffer readMessage (final ByteBuffer message ) throws AEADBadTagException {
10191030 checkInboundMessageSize (message .remaining ());
@@ -1049,7 +1060,8 @@ public ByteBuffer readMessage(final ByteBuffer message) throws AEADBadTagExcepti
10491060 * match the calculated value
10501061 * @throws ShortBufferException if {@code payload} does not have enough remaining capacity to hold the plaintext of
10511062 * the payload included in the given handshake message
1052- * @throws IllegalArgumentException if the given message is too short to contain the expected handshake message
1063+ * @throws IllegalArgumentException if the given message is too short to contain the expected handshake message or if
1064+ * the given message is larger than the maximum allowed Noise handshake message size
10531065 *
10541066 * @see #getPayloadLength(int)
10551067 */
0 commit comments