Package org.xnio.sasl

# Class SaslWrapper

java.lang.Object
org.xnio.sasl.SaslWrapper

public abstract class SaslWrapper extends Object
A wrapper delegation class for SASL that presents the same wrap/unwrap API regardless of whether it is dealing with a SASL client or server.

Author:
  David M. Lloyd

## Constructor Summary

Constructors
Constructor
Description
`SaslWrapper()`

## Method Summary

Modifier and Type
Method
Description
`static SaslWrapper`
`create(SaslClient saslClient)`
Create a SASL wrapper for a SASL client.
`static SaslWrapper`
`create(SaslServer saslServer)`
Create a SASL wrapper for a SASL server.
`final byte[]`
`unwrap(byte[] bytes)`
Unwrap a message.
`abstract byte[]`
`unwrap(byte[] bytes, int off, int len)`
Unwrap a message.
`abstract byte[]`
`unwrap(ByteBuffer source)`
Unwrap a message.
`final void`
`unwrap(ByteBuffer destination, ByteBuffer source)`
Unwrap a message.
`final byte[]`
`wrap(byte[] bytes)`
Wrap a message.
`abstract byte[]`
`wrap(byte[] bytes, int off, int len)`
Wrap a message.
`abstract byte[]`
`wrap(ByteBuffer source)`
Wrap a message.
`final void`
`wrap(ByteBuffer destination, ByteBuffer source)`
Wrap a message.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SaslWrapper

public SaslWrapper()

## Method Details

### wrap

public abstract byte[] wrap(byte[] bytes, int off, int len) throws SaslException
Wrap a message.

Parameters:
  `bytes` - the incoming message
  `off` - the offset into the byte array
  `len` - the length of the byte array to wrap
Returns:
  the wrap result
Throws:
  `SaslException` - if a problem occurs

### wrap

public final byte[] wrap(byte[] bytes) throws SaslException
Wrap a message.

Parameters:
  `bytes` - the incoming message
Returns:
  the wrap result
Throws:
  `SaslException` - if a problem occurs

### wrap

public abstract byte[] wrap(ByteBuffer source) throws SaslException
Wrap a message.

Parameters:
  `source` - the buffer from which bytes should be read
Returns:
  the wrap result
Throws:
  `SaslException` - if a problem occurs

### unwrap

public abstract byte[] unwrap(byte[] bytes, int off, int len) throws SaslException
Unwrap a message.

Parameters:
  `bytes` - the incoming message
  `off` - the offset into the byte array
  `len` - the length of the byte array to wrap
Returns:
  the unwrap result
Throws:
  `SaslException` - if a problem occurs

### unwrap

public final byte[] unwrap(byte[] bytes) throws SaslException
Unwrap a message.

Parameters:
  `bytes` - the incoming message
Returns:
  the unwrap result
Throws:
  `SaslException` - if a problem occurs

### unwrap

public abstract byte[] unwrap(ByteBuffer source) throws SaslException
Unwrap a message.

Parameters:
  `source` - the buffer from which bytes should be read
Returns:
  the unwrap result
Throws:
  `SaslException` - if a problem occurs

### wrap

public final void wrap(ByteBuffer destination, ByteBuffer source) throws SaslException
Wrap a message. Wrapping occurs from the source buffer to the destination idea.

The `source` buffer should have its position and remaining length set to encompass exactly one SASL 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.

Parameters:
  `destination` - the buffer into which bytes should be written
  `source` - the buffers from which bytes should be read
Throws:
  `SaslException` - if a SASL error occurs
See Also:
  - `SaslClient.wrap(byte[], int, int)`
  - `SaslServer.wrap(byte[], int, int)`

### unwrap

public final void unwrap(ByteBuffer destination, ByteBuffer source) throws SaslException
Unwrap a message. Unwrapping occurs from the source buffer to the destination idea.

The `source` buffer should have its position and remaining length set to encompass exactly one SASL 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.

Parameters:
  `destination` - the buffer into which bytes should be written
  `source` - the buffers from which bytes should be read
Throws:
  `SaslException` - if a SASL error occurs
See Also:
  - `SaslClient.unwrap(byte[], int, int)`

### create

public static SaslWrapper create(SaslClient saslClient)
Create a SASL wrapper for a SASL client.

Parameters:
  `saslClient` - the SASL client
Returns:
  the wrapper

### create

public static SaslWrapper create(SaslServer saslServer)
Create a SASL wrapper for a SASL server.

Parameters:
  `saslServer` - the SASL server
Returns:
  the wrapper