org.opcfoundation.ua.transport.tcp.impl
Class ChunkFactory

java.lang.Object
  extended by org.opcfoundation.ua.utils.bytebuffer.ByteBufferFactory
      extended by org.opcfoundation.ua.transport.tcp.impl.ChunkFactory
Direct Known Subclasses:
ChunkFactory.AcknowledgeChunkFactory, ChunkFactory.AsymmMsgChunkFactory, ChunkFactory.ErrorMessageChunkFactory, ChunkFactory.HelloChunkFactory

public class ChunkFactory
extends ByteBufferFactory

Chunk factory constructs byte buffers to be used for writing. The byte buffer will be backed by an array that can fit the chunk. The writable portion of the byte buffer (position -> limit) reflects to writable plaintext region.

Padding and the size of the message is pre-written to the chunk.

Author:
Toni Kalajainen (toni.kalajainen@vtt.fi), Mikko Salonen

Nested Class Summary
static class ChunkFactory.AcknowledgeChunkFactory
           
static class ChunkFactory.AsymmMsgChunkFactory
           
static class ChunkFactory.ErrorMessageChunkFactory
           
static class ChunkFactory.HelloChunkFactory
           
 
Field Summary
 int cipherBlockSize
           
 int maxChunkSize
           
 int maxPlaintextSize
           
 int messageHeaderSize
           
 int securityHeader
           
 MessageSecurityMode securityMode
           
 int sequenceHeader
           
 int signatureSize
           
 
Fields inherited from class org.opcfoundation.ua.utils.bytebuffer.ByteBufferFactory
BIG_ENDIAN_HEAP_BYTEBUFFER_FACTORY, DEFAULT_ENDIAN_HEAP_BYTEBUFFER_FACTORY, LITTLE_ENDIAN_HEAP_BYTEBUFFER_FACTORY
 
Constructor Summary
ChunkFactory(int maxChunkSize, int messageHeaderSize, int securityHeaderSize, int sequenceHeaderSize, int signatureSize, int cipherBlockSize, MessageSecurityMode securityMode, int keySize)
          Constructor for ChunkFactory.
 
Method Summary
 ByteBuffer allocate(int bodySize)
          allocate.
 void encryptChunk(ByteBuffer chunk)
          encryptChunk.
 ByteBuffer expandToCompleteChunk(ByteBuffer plaintext)
          Expand allocated bytebuffer to complete chunk.
 ByteBuffer[] expandToCompleteChunk(ByteBuffer[] plaintexts)
          expandToCompleteChunk.
protected  int getMinimumPadding()
          getMinimumPadding.
 void signChunk(ByteBuffer chunk)
          signChunk.
protected  void writePadding(int paddingPosition, int padding, ByteBuffer result)
          writePadding.
protected  void writePaddingSize(int paddingPosition, int paddingSize, ByteBuffer result)
          writePaddingSize.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxChunkSize

public int maxChunkSize

maxPlaintextSize

public int maxPlaintextSize

messageHeaderSize

public int messageHeaderSize

securityHeader

public int securityHeader

sequenceHeader

public int sequenceHeader

cipherBlockSize

public int cipherBlockSize

signatureSize

public int signatureSize

securityMode

public MessageSecurityMode securityMode
Constructor Detail

ChunkFactory

public ChunkFactory(int maxChunkSize,
                    int messageHeaderSize,
                    int securityHeaderSize,
                    int sequenceHeaderSize,
                    int signatureSize,
                    int cipherBlockSize,
                    MessageSecurityMode securityMode,
                    int keySize)

Constructor for ChunkFactory.

Parameters:
maxChunkSize - a int.
messageHeaderSize - a int.
securityHeaderSize - a int.
sequenceHeaderSize - a int.
signatureSize - a int.
cipherBlockSize - a int.
securityMode - a MessageSecurityMode object.
keySize - a int.
Method Detail

getMinimumPadding

protected int getMinimumPadding()

getMinimumPadding.

Returns:
a int.

allocate

public ByteBuffer allocate(int bodySize)

allocate.

Allocate chunk for a message with a given body size.

Specified by:
allocate in class ByteBufferFactory
Parameters:
bodySize - a int.
Returns:
a ByteBuffer object.

writePadding

protected void writePadding(int paddingPosition,
                            int padding,
                            ByteBuffer result)

writePadding.

Parameters:
paddingPosition - a int.
paddingPosition -
padding - the size of the whole padding; padding, padding fill, extra padding byte
result - a ByteBuffer object.

writePaddingSize

protected void writePaddingSize(int paddingPosition,
                                int paddingSize,
                                ByteBuffer result)

writePaddingSize.

Parameters:
paddingPosition - a int.
paddingSize - a int.
result - a ByteBuffer object.

signChunk

public void signChunk(ByteBuffer chunk)

signChunk.

Parameters:
chunk - a ByteBuffer object.

encryptChunk

public void encryptChunk(ByteBuffer chunk)

encryptChunk.

Parameters:
chunk - a ByteBuffer object.

expandToCompleteChunk

public ByteBuffer expandToCompleteChunk(ByteBuffer plaintext)
Expand allocated bytebuffer to complete chunk. ByteBuffer allocated with allocate() returns a buffer that has only plaintext as writable portion. This method expands the ByteBuffer to include header and footer. The result is rewound.

Parameters:
plaintext - a ByteBuffer object.
Returns:
chunk

expandToCompleteChunk

public ByteBuffer[] expandToCompleteChunk(ByteBuffer[] plaintexts)

expandToCompleteChunk.

Parameters:
plaintexts - an array of ByteBuffer objects.
Returns:
an array of ByteBuffer objects.


Copyright © 2018. All rights reserved.