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 SSHPacket
inputBuffer
Buffer where as-yet undecoded data livesprivate org.slf4j.Logger
log
private byte[]
macResult
MAC result is stored hereprivate static int
MAX_PACKET_LEN
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?private SSHPacketHandler
packetHandler
What we pass decoded packets toprivate int
packetLength
-1 if packet length not yet been decoded, else the packet lengthprivate SSHPacket
uncompressBuffer
Used 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 void
checkMAC(byte[] data)
private void
checkPacketLength(int len)
private int
decode()
Returns advised number of bytes that should be made available in decoderBuffer before the method should be called again.private SSHPacket
decompressed()
private void
decryptBuffer(int offset, int length)
private int
decryptLength()
private int
decryptLengthAAD()
(package private) Compression.Mode
getCompressionType()
(package private) int
getMaxPacketLength()
(package private) int
received(byte[] b, int len)
Addslen
bytes fromb
to the decoder buffer.(package private) void
setAlgorithms(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 SSHException
Returns 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 SSHException
Addslen
bytes fromb
to 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 theSSHPacketHandler
this 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:
setAlgorithms
in classConverter
-
getCompressionType
Compression.Mode getCompressionType()
- Specified by:
getCompressionType
in classConverter
-
getMaxPacketLength
int getMaxPacketLength()
-
-