diff --git a/api/src/main/java/org/xnio/sasl/SaslUtils.java b/api/src/main/java/org/xnio/sasl/SaslUtils.java index b390aa45c..9fa9a6deb 100644 --- a/api/src/main/java/org/xnio/sasl/SaslUtils.java +++ b/api/src/main/java/org/xnio/sasl/SaslUtils.java @@ -108,8 +108,8 @@ public static boolean evaluateResponse(SaslServer server, ByteBuffer destination * Wrap a message. Wrapping occurs from the source buffer to the destination idea. *

* The {@code source} buffer should have its position and remaining length set to encompass exactly one SASL - * message. The SASL message itself does not encode any length information so it is up to the protocol implementer - * to ensure that the message is properly framed. + * message (without the length field). The SASL message itself does not encode any length information so it is up + * to the protocol implementer to ensure that the message is properly framed. * * @param client the SASL client to wrap with * @param destination the buffer into which bytes should be written @@ -120,7 +120,9 @@ public static boolean evaluateResponse(SaslServer server, ByteBuffer destination public static void wrap(SaslClient client, ByteBuffer destination, ByteBuffer source) throws SaslException { final byte[] result; final int len = source.remaining(); - if (source.hasArray()) { + if (len == 0) { + result = client.wrap(EMPTY_BYTES, 0, len); + } else if (source.hasArray()) { final byte[] array = source.array(); final int offs = source.arrayOffset(); source.position(source.position() + len); @@ -135,8 +137,8 @@ public static void wrap(SaslClient client, ByteBuffer destination, ByteBuffer so * Wrap a message. Wrapping occurs from the source buffer to the destination idea. *

* The {@code source} buffer should have its position and remaining length set to encompass exactly one SASL - * message. The SASL message itself does not encode any length information so it is up to the protocol implementer - * to ensure that the message is properly framed. + * message (without the length field). The SASL message itself does not encode any length information so it is up + * to the protocol implementer to ensure that the message is properly framed. * * @param server the SASL server to wrap with * @param destination the buffer into which bytes should be written @@ -148,7 +150,7 @@ public static void wrap(SaslServer server, ByteBuffer destination, ByteBuffer so final byte[] result; final int len = source.remaining(); if (len == 0) { - result = server.unwrap(EMPTY_BYTES, 0, len); + result = server.wrap(EMPTY_BYTES, 0, len); } else if (source.hasArray()) { final byte[] array = source.array(); final int offs = source.arrayOffset(); @@ -164,8 +166,8 @@ public static void wrap(SaslServer server, ByteBuffer destination, ByteBuffer so * Unwrap a message. Unwrapping occurs from the source buffer to the destination idea. *

* The {@code source} buffer should have its position and remaining length set to encompass exactly one SASL - * message. The SASL message itself does not encode any length information so it is up to the protocol implementer - * to ensure that the message is properly framed. + * message (without the length field). The SASL message itself does not encode any length information so it is up + * to the protocol implementer to ensure that the message is properly framed. * * @param client the SASL client to unwrap with * @param destination the buffer into which bytes should be written @@ -193,8 +195,8 @@ public static void unwrap(SaslClient client, ByteBuffer destination, ByteBuffer * Unwrap a message. Unwrapping occurs from the source buffer to the destination idea. *

* The {@code source} buffer should have its position and remaining length set to encompass exactly one SASL - * message. The SASL message itself does not encode any length information so it is up to the protocol implementer - * to ensure that the message is properly framed. + * message (without the length field). The SASL message itself does not encode any length information so it is up + * to the protocol implementer to ensure that the message is properly framed. * * @param server the SASL server to unwrap with * @param destination the buffer into which bytes should be written