com.mindbright.ssh2
public class SSH2TransportPDU extends SSH2DataBuffer
There is a difference bwteeen incoming and outgoing PDUs. The latter have extra space allocated in them to help speed up the encryption process.
This class makes an effort to avoid copying data wherever possible.
Modifier and Type | Field and Description |
---|---|
static SSH2TransportPDU |
factoryInstance |
static int |
PACKET_DEFAULT_SIZE |
static int |
PACKET_MAX_SIZE |
static int |
PACKET_MIN_SIZE |
protected int |
padSize |
static int |
pktDefaultSize |
protected int |
pktSize |
protected int |
pktType |
protected int |
totSizeCompressed |
protected int |
totSizeUncompressed |
BOOLEAN_FALSE, BOOLEAN_TRUE, data, rPos, wPos
Modifier | Constructor and Description |
---|---|
protected |
SSH2TransportPDU() |
protected |
SSH2TransportPDU(int pktType,
int bufSize)
Constructor which creates a prefabricated packet.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkMac(javax.crypto.Mac mac,
int macSize) |
static SSH2TransportPDU |
createIncomingPacket()
Have the factory create a PDU for an incoming packet.
|
static SSH2TransportPDU |
createIncomingPacket(int bufSize)
Have the factory create a PDU for an incoming packet.
|
protected SSH2TransportPDU |
createInPDU(int bufSize)
Create a new PDU to use for incoming packets.
|
static SSH2TransportPDU |
createOutgoingPacket(int pktType)
Have the factory create a PDU for an outgoing packet.
|
static SSH2TransportPDU |
createOutgoingPacket(int pktType,
int bufSize)
Have the factory create a PDU for an outgoing packet.
|
protected SSH2TransportPDU |
createOutPDU(int pktType,
int bufSize)
Create a new PDU for an outgoing packet.
|
protected SSH2TransportPDU |
createPDU(int pktType,
int bufSize)
Create a new PDU for a packet.
|
static SSH2Transport.TransceiverContext |
createTransceiverContext(java.lang.String cipherName,
int cipherDiscard,
java.lang.String macName,
int macLength,
java.lang.String compName,
NonBlockingInput in)
Static function which creates a transceiver context with the
mentioned algorithms.
|
SSH2Transport.TransceiverContext |
createTransceiverContextImpl(java.lang.String cipherName,
int cipherDiscard,
java.lang.String macName,
int macLength,
java.lang.String compName,
NonBlockingInput in)
An implementation which actually creates a transceiver context.
|
void |
fillData(byte[] buf,
int bufpos,
int n) |
int |
getCompressedSize() |
int |
getNeededBytes() |
int |
getPayloadLength()
Get the length of the payload.
|
int |
getPayloadOffset()
Get the offset in the data buffer where the payload starts.
|
int |
getType() |
int |
getUncompressedSize() |
void |
initReceive(int seqNum,
SSH2Transport.TransceiverContext context)
Prepare this PDU for receiving data.
|
SSH2TransportPDU |
makeCopy()
Create a copy of this PDU.
|
boolean |
processData()
Read and decrypt data from the given stream.
|
void |
release()
Release this PDU.
|
static void |
setFactoryInstance(SSH2TransportPDU factory)
Register a factor which handles the creation and destruction of
incoming and outgoing packets.
|
void |
setType(int pktType) |
java.lang.String |
toString()
Creates a string representation of this PDU.
|
void |
writeByte(int b) |
void |
writeRaw(byte[] raw,
int off,
int len) |
void |
writeString(byte[] str,
int off,
int len) |
void |
writeTo(NonBlockingOutput out,
int seqNum,
SSH2Transport.TransceiverContext context,
SecureRandomAndPad rand)
Encrypts and writes an outgoing packet to the stream.
|
getData, getMaxReadSize, getMaxSize, getMaxWriteSize, getRPos, getWPos, readBigInt, readBigIntBits, readBoolean, readByte, readInt, readJavaString, readLong, readRaw, readRaw, readRestRaw, readString, readString, readUInt, reset, resize, setData, setRPos, setWPos, writeBigInt, writeBigIntBits, writeBoolean, writeInt, writeInt, writeLong, writeRaw, writeString, writeString, writeUTF8String
public static final int PACKET_DEFAULT_SIZE
public static final int PACKET_MIN_SIZE
public static final int PACKET_MAX_SIZE
public static int pktDefaultSize
public static SSH2TransportPDU factoryInstance
protected int pktSize
protected int padSize
protected int pktType
protected int totSizeCompressed
protected int totSizeUncompressed
protected SSH2TransportPDU()
protected SSH2TransportPDU(int pktType, int bufSize)
pktType
- Type of packet to create.bufSize
- How many bytes it should have room for.protected SSH2TransportPDU createInPDU(int bufSize)
bufSize
- How many bytes it should have room for.protected SSH2TransportPDU createOutPDU(int pktType, int bufSize)
pktType
- Type of packet to create.bufSize
- How many bytes it should have room for.protected SSH2TransportPDU createPDU(int pktType, int bufSize)
pktType
- Type of packet to create.bufSize
- How many bytes it should have room for.public static final void setFactoryInstance(SSH2TransportPDU factory)
public static final SSH2TransportPDU createIncomingPacket(int bufSize)
bufSize
- How many bytes it should have room for.public static final SSH2TransportPDU createIncomingPacket()
public static final SSH2TransportPDU createOutgoingPacket(int pktType, int bufSize)
pktType
- Type of packet to create.bufSize
- How many bytes it should have room for.public static final SSH2TransportPDU createOutgoingPacket(int pktType)
pktType
- Type of packet to create.public static final SSH2Transport.TransceiverContext createTransceiverContext(java.lang.String cipherName, int cipherDiscard, java.lang.String macName, int macLength, java.lang.String compName, NonBlockingInput in) throws java.lang.Exception
cipherName
- Name of cipher algorithm to use.cipherDiscard
- How many bytes to discard after key init.macName
- Name of message authentication cipher to use.macLength
- How many bytes of the mac digest to usecompName
- Name of compression algorithm to use.java.lang.Exception
public void release()
public SSH2TransportPDU makeCopy()
public int getType()
public void setType(int pktType)
public int getPayloadLength()
public int getPayloadOffset()
public int getCompressedSize()
public int getUncompressedSize()
public void initReceive(int seqNum, SSH2Transport.TransceiverContext context)
seqNum
- Sequence number of packet.context
- Transceiver context.public int getNeededBytes()
public void fillData(byte[] buf, int bufpos, int n)
public boolean processData() throws SSH2Exception, javax.crypto.ShortBufferException, java.security.GeneralSecurityException
SSH2Exception
javax.crypto.ShortBufferException
java.security.GeneralSecurityException
protected void checkMac(javax.crypto.Mac mac, int macSize) throws SSH2MacCheckException, java.security.GeneralSecurityException
SSH2MacCheckException
java.security.GeneralSecurityException
public final void writeByte(int b)
writeByte
in class SSH2DataBuffer
public final void writeString(byte[] str, int off, int len)
writeString
in class SSH2DataBuffer
public final void writeRaw(byte[] raw, int off, int len)
writeRaw
in class SSH2DataBuffer
public void writeTo(NonBlockingOutput out, int seqNum, SSH2Transport.TransceiverContext context, SecureRandomAndPad rand) throws java.io.IOException, java.security.GeneralSecurityException, SSH2CompressionException
out
- Stream to write resulting data to.seqNum
- Sequence number of packet.context
- Transceiver context to use.rand
- An object from which random numbers and padding
data is read.java.io.IOException
java.security.GeneralSecurityException
SSH2CompressionException
public java.lang.String toString()
toString
in class java.lang.Object
public SSH2Transport.TransceiverContext createTransceiverContextImpl(java.lang.String cipherName, int cipherDiscard, java.lang.String macName, int macLength, java.lang.String compName, NonBlockingInput in) throws java.lang.Exception
cipherName
- Name of cipher algorithm to use.cipherDiscard
- How many bytes to discard after key init.macName
- Name of message authentication cipher to use.macLength
- How many bytes of the mac digest to usecompName
- Name of compression algorithm to use.java.lang.Exception