Package net.schmizz.sshj.transport
Class Decoder
- java.lang.Object
-
- net.schmizz.sshj.transport.Converter
-
- net.schmizz.sshj.transport.Decoder
-
final class Decoder extends Converter
Decodes packets from the SSH binary protocol per the current algorithms.
-
-
Field Summary
Fields Modifier and Type Field Description private SSHPacketinputBufferBuffer where as-yet undecoded data livesprivate org.slf4j.Loggerlogprivate byte[]macResultMAC result is stored hereprivate static intMAX_PACKET_LENprivate intneededHow many bytes do we need, before a call to decode() can succeed at decoding at least packet length, OR the whole packet?private SSHPacketHandlerpacketHandlerWhat we pass decoded packets toprivate intpacketLength-1 if packet length not yet been decoded, else the packet lengthprivate SSHPacketuncompressBufferUsed in case compression is active to store the uncompressed data-
Fields inherited from class net.schmizz.sshj.transport.Converter
authed, authMode, cipher, cipherSize, compression, etm, mac, seq
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckMAC(byte[] data)private voidcheckPacketLength(int len)private intdecode()Returns advised number of bytes that should be made available in decoderBuffer before the method should be called again.private SSHPacketdecompressed()private voiddecryptBuffer(int offset, int length)private intdecryptLength()private intdecryptLengthAAD()(package private) Compression.ModegetCompressionType()(package private) intgetMaxPacketLength()(package private) intreceived(byte[] b, int len)Addslenbytes frombto the decoder buffer.(package private) voidsetAlgorithms(Cipher cipher, MAC mac, Compression compression)-
Methods inherited from class net.schmizz.sshj.transport.Converter
getSequenceNumber, isSequenceNumberAtMax, resetSequenceNumber, setAuthenticated, usingCompression
-
-
-
-
Field Detail
-
MAX_PACKET_LEN
private static final int MAX_PACKET_LEN
- See Also:
- Constant Field Values
-
log
private final org.slf4j.Logger log
-
packetHandler
private final SSHPacketHandler packetHandler
What we pass decoded packets to
-
inputBuffer
private final SSHPacket inputBuffer
Buffer where as-yet undecoded data lives
-
uncompressBuffer
private final SSHPacket uncompressBuffer
Used in case compression is active to store the uncompressed data
-
macResult
private byte[] macResult
MAC result is stored here
-
packetLength
private int packetLength
-1 if packet length not yet been decoded, else the packet length
-
needed
private int needed
How many bytes do we need, before a call to decode() can succeed at decoding at least packet length, OR the whole packet?
-
-
Constructor Detail
-
Decoder
Decoder(Transport packetHandler)
-
-
Method Detail
-
decode
private int decode() throws SSHExceptionReturns advised number of bytes that should be made available in decoderBuffer before the method should be called again.- Returns:
- number of bytes needed before further decoding possible
- Throws:
SSHException
-
checkMAC
private void checkMAC(byte[] data) throws TransportException- Throws:
TransportException
-
decompressed
private SSHPacket decompressed() throws TransportException
- Throws:
TransportException
-
decryptLengthAAD
private int decryptLengthAAD() throws TransportException- Throws:
TransportException
-
decryptLength
private int decryptLength() throws TransportException- Throws:
TransportException
-
decryptBuffer
private void decryptBuffer(int offset, int length)
-
checkPacketLength
private void checkPacketLength(int len) throws TransportException- Throws:
TransportException
-
received
int received(byte[] b, int len) throws SSHExceptionAddslenbytes frombto the decoder buffer. When a packet has been successfully decoded, hooks in toSSHPacketHandler.handle(net.schmizz.sshj.common.Message, net.schmizz.sshj.common.SSHPacket)of theSSHPacketHandlerthis decoder was initialized with. Returns the number of bytes expected in the next call in order to decode the packet length, and if the packet length has already been decoded; to decode the payload. This number is accurate and should be taken to heart.- Throws:
SSHException
-
setAlgorithms
void setAlgorithms(Cipher cipher, MAC mac, Compression compression)
- Overrides:
setAlgorithmsin classConverter
-
getCompressionType
Compression.Mode getCompressionType()
- Specified by:
getCompressionTypein classConverter
-
getMaxPacketLength
int getMaxPacketLength()
-
-