Top Description Fields Constructors Methods
org.apache.sshd.common.util.buffer

public abstract Class Buffer

extends Object
implements Readable
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.util.Readable
Known Direct Subclasses
org.apache.sshd.common.util.buffer.ByteArrayBuffer
Imports
java.math.BigInteger, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .StandardCharsets, java.security.GeneralSecurityException, .KeyFactory, .KeyPair, .NoSuchAlgorithmException, .PrivateKey, .PublicKey, java.security.interfaces.DSAParams, .DSAPrivateKey, .DSAPublicKey, .ECPrivateKey, .ECPublicKey, .RSAPrivateCrtKey, .RSAPublicKey, java.security.spec.DSAPrivateKeySpec, .DSAPublicKeySpec, .ECParameterSpec, .ECPoint, .ECPrivateKeySpec, .ECPublicKeySpec, .InvalidKeySpecException, .RSAPrivateCrtKeySpec, .RSAPublicKeySpec, java.util.ArrayList, .Arrays, .Collection, .Collections, .LinkedList, .List, .Objects, java.util.function.IntUnaryOperator, java.util.logging.Level, org.apache.sshd.common.PropertyResolver, .SshConstants, .SshException, org.apache.sshd.common.cipher.ECCurves, org.apache.sshd.common.config.keys.KeyUtils, .OpenSshCertificate, .UnsupportedSshPublicKey, org.apache.sshd.common.config.keys.u2f.SecurityKeyPublicKey, org.apache.sshd.common.keyprovider.KeyPairProvider, org.apache.sshd.common.util.GenericUtils, .NumberUtils, .Readable, org.apache.sshd.common.util.buffer.keys.BufferPublicKeyParser, org.apache.sshd.common.util.logging.SimplifiedLog, org.apache.sshd.common.util.security.SecurityUtils

Provides an abstract message buffer for encoding SSH messages
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
protected final byte[]

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public abstract byte[]

Returns:

The raw underlying data bytes
array
()

public abstract int

Returns:

Number of bytes that can still be written without re-sizing the internal buffer
capacity
()

public Buffer

Returns:

Reference to this buffer
clear
()

Reset read/write positions to zero - Note: zeroes any previously existing data

public abstract Buffer

Returns:

Reference to this buffer
clear
(boolean
Whether to zero any previously existing data
wipeData
)

Reset read/write positions to zero

public abstract void
compact()

"Shift" the internal data so that reading starts from position zero.

protected abstract void
copyRawBytes(int offset, byte[] buf, int pos, int len)

public void
dumpHex(SimplifiedLog logger, String prefix, PropertyResolver resolver)

public void
dumpHex(SimplifiedLog logger, Level level, String prefix, PropertyResolver resolver)

public int

Returns:

Same as input if validation successful
ensureAvailable
(int
Requested data in bytes
reqLen
)

Makes sure the buffer contains enough data to accommodate the requested length

public Buffer
ensureCapacity(int capacity)

public abstract Buffer

Returns:

This buffer instance
ensureCapacity
(int
The required capacity
capacity
,
IntUnaryOperator
An IntUnaryOperator that is invoked if the current capacity is insufficient. The argument is the minimum required new data length, the function result should be the effective new data length to be allocated - if less than minimum then an exception is thrown
growthFactor
)

protected KeyPair
extractEC(String expectedCurveName, ECParameterSpec spec)

public Collection<String>

Returns:

The remaining data as a list of strings
getAvailableStrings
()

public Collection<String>

Returns:

The remaining data as a list of strings
getAvailableStrings
(Charset
The Charset to use for the strings
charset
)

public boolean
public byte
public byte[]
public abstract byte[]

Returns:

The bytes consumed so far
getBytesConsumed
()

public abstract byte[]

Returns:

The bytes consumed since the given position
getBytesConsumed
(int from)

public List<OpenSshCertificate.CertificateOption>
public List<OpenSshCertificate.CertificateOption>

Returns:

the parsed result, never null, but possibly empty
getCertificateOptions
(Charset
Charset to use for converting bytes to characters
charset
)

According to PROTOCOL.certkeys: Critical Options is a set of bytes that is [overall length][name(string)][[length of buffer][[length of string][data(string)]]]...

public byte[]
public int
public KeyPair
public long
public BigInteger
public byte[]
public List<String>

Returns:

The parsed result
getNameList
()

According to RFC 4251: A name-list is represented as a uint32 containing its length (number of bytes that follow) followed by a comma-separated list of zero or more names.

public List<String>
public List<String>
getNameList(char separator)

public List<String>

Returns:

A List of the parsed values
getNameList
(Charset
The Charset to use to read the string
charset
,
char
The separator
separator
)

Parses a string that contains values separated by a delimiter

public PublicKey
public PublicKey

Returns:

The extracted PublicKey - may be null if the parser so decided
getPublicKey
(BufferPublicKeyParser<? extends PublicKey>
A BufferPublicKeyParser to extract the key from the buffer - never null
parser
)

public void
getRawBytes(byte[] buf)

public PublicKey
public PublicKey

Returns:

The extracted PublicKey - may be null if the parser so decided
getRawPublicKey
(BufferPublicKeyParser<? extends PublicKey>
A BufferPublicKeyParser to extract the key from the buffer - never null
parser
)

public short
public String

Returns:

Reads a UTF-8 encoded string
getString
()

public abstract String

Returns:

The read string
getString
(Charset
The Charset to use for the string bytes
charset
)

Reads a string using a given charset.

public Collection<String>

Returns:

A Collection of the read strings
getStringList
(boolean
If true then there is a 32-bit value indicating the number of strings to read. Otherwise, the method will use a "greedy" reading of strings while more data available.
usePrependedLength
)

public Collection<String>

Returns:

A Collection of the read strings
getStringList
(boolean
If true then there is a 32-bit value indicating the number of strings to read. Otherwise, the method will use a "greedy" reading of strings while more data available.
usePrependedLength
,
Charset
The Charset to use for the strings
charset
)

public List<String>

Returns:

A List with the specified number of strings
getStringList
(int
The exact number of strings to read - can be zero
count
)

public List<String>

Returns:

A List with the specified number of strings
getStringList
(int
The exact number of strings to read - can be zero
count
,
Charset
The Charset of the strings
charset
)

public int
public long
public int
private static boolean
isSensitiveData(int cmd)

public boolean
isValidMessageStructure(Class<?>... fieldTypes)

public boolean
public void
putAndWipeBytes(byte[]
The buffer to add - OK if null
b
)

Adds the bytes to the buffer and wipes the data from the input buffer after having added it - useful for sensitive information such as password

public void
putAndWipeBytes(byte[] b, int off, int len)

public void
putAndWipeChars(char[]
The characters to put in the buffer - may be null/empty
chars
)

Zeroes the input array after having put the characters in the buffer - useful for sensitive information such as passwords

public void
putAndWipeChars(char[] chars, int offset, int len)

public void
putAndWipeChars(char[] chars, Charset charset)

public void
putAndWipeChars(char[] chars, int offset, int len, Charset charset)

public void
putBoolean(boolean b)

public void
public abstract int
putBuffer(Readable buffer, boolean expand)

public abstract void
public void
putBufferedData(Object
The (never null) buffer object to put
buffer
)

Checks if the buffer argument is an array of bytes, a Readable instance or a ByteBuffer and invokes the appropriate putXXX method.

public void
putByte(byte b)

public void
putBytes(byte[] b)

public void
putBytes(byte[] b, int off, int len)

public void
public void
putCertificateOptions(List<OpenSshCertificate.CertificateOption>
to write into the buffer, may be null or empty but must not contain null elements
options
,
Charset
The Charset to use for string options
charset
)

According to PROTOCOL.certkeys: Certificate Options is a set of bytes that is [overall length][name(string)][[length of buffer][[length of string][data(string)]]]...

public void
putChars(char[] chars)

public void
putChars(char[] chars, int offset, int len)

public void
putChars(char[] chars, Charset charset)

public void
putChars(char[] chars, int offset, int len, Charset charset)

public void
putInt(long i)

public void
public void
putLong(long
The 64-bit value
i
)

Writes 64 bits

public void
public void
putMPInt(byte[] mpInt)

public void
putNameList(Collection<String>
The name list to put
names
)

According to RFC 4251: A name-list is represented as a uint32 containing its length (number of bytes that follow) followed by a comma-separated list of zero or more names.

public void
public void
putNameList(Collection<String> names, char separator)

public void
putNameList(Collection<String>
The names to set
names
,
Charset
The Charset to use to encode the string
charset
,
char
The separator
separator
)

Adds a string that contains values separated by a delimiter

public void
putOptionalBufferedData(Object
The buffered data object to inspect
buffer
)

Checks if the buffer argument is an array of bytes, a Readable instance or a ByteBuffer and invokes the appropriate putXXX method.

public void
public void
putRawBytes(byte[] d)

public abstract void
putRawBytes(byte[] d, int off, int len)

public void
public void
public void
putShort(int
The 16-bit value
i
)

Writes 16 bits

public void
putString(String string)

public void
putString(String string, Charset charset)

public void
putStringList(Collection<?>
The objects to be encoded in the buffer - OK if null/empty
objects
,
boolean
If true then the list is preceded by a 32-bit count of the number of members in the list
prependLength
)

Encodes the toString value of each member.

public void
putStringList(Collection<?>
The objects to be encoded in the buffer - OK if null/empty
objects
,
Charset
The Charset to use for encoding
charset
,
boolean
If true then the list is preceded by a 32-bit count of the number of members in the list
prependLength
)

Encodes the toString value of each member

public void
putUInt(long
The 32-bit value
i
)

Writes 32 bits

public byte

Returns:

The byte at the specified position without changing the current read position

Note

no validation is made whether the position lies within array boundaries

rawByte
(int
A position in the raw underlying data bytes
pos
)

public long

Returns:

The unsigned 32 bit integer at the specified position without changing the current read position

Note

no validation is made whether the position and the required extra 4 bytes lie within array boundaries

rawUInt
(int
A position in the raw underlying data bytes
pos
)

public abstract int

Returns:

Current reading position
rpos
()

public abstract void
rpos(int
Set current reading position
rpos
)

protected abstract int

Returns:

Current size of underlying backing data bytes array
size
()

public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public abstract int

Returns:

Current writing position
wpos
()

public abstract void
wpos(int
Set current writing position - Note: if necessary, the underlying data buffer will be increased so as to allow writing from the new position
wpos
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait