public abstract class Buffer extends Object implements Readable
Modifier and Type | Field and Description |
---|---|
protected byte[] |
workBuf |
Modifier | Constructor and Description |
---|---|
protected |
Buffer() |
Modifier and Type | Method and Description |
---|---|
abstract byte[] |
array() |
abstract int |
capacity() |
Buffer |
clear()
Reset read/write positions to zero - Note: zeroes any previously existing data
|
abstract Buffer |
clear(boolean wipeData)
Reset read/write positions to zero
|
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) |
void |
dumpHex(SimplifiedLog logger,
Level level,
String prefix,
PropertyResolver resolver) |
void |
dumpHex(SimplifiedLog logger,
String prefix,
PropertyResolver resolver) |
int |
ensureAvailable(int reqLen)
Makes sure the buffer contains enough data to accommodate the requested length
|
Buffer |
ensureCapacity(int capacity) |
abstract Buffer |
ensureCapacity(int capacity,
IntUnaryOperator growthFactor) |
protected KeyPair |
extractEC(String expectedCurveName,
ECParameterSpec spec) |
Collection<String> |
getAvailableStrings() |
Collection<String> |
getAvailableStrings(Charset charset) |
boolean |
getBoolean() |
byte |
getByte() |
byte[] |
getBytes() |
abstract byte[] |
getBytesConsumed() |
List<OpenSshCertificate.CertificateOption> |
getCertificateOptions() |
List<OpenSshCertificate.CertificateOption> |
getCertificateOptions(Charset 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)]]]...
|
byte[] |
getCompactData() |
int |
getInt() |
KeyPair |
getKeyPair() |
long |
getLong() |
BigInteger |
getMPInt() |
byte[] |
getMPIntAsBytes() |
List<String> |
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.
|
List<String> |
getNameList(char separator) |
List<String> |
getNameList(Charset charset) |
List<String> |
getNameList(Charset charset,
char separator)
Parses a string that contains values separated by a delimiter
|
PublicKey |
getPublicKey() |
PublicKey |
getPublicKey(BufferPublicKeyParser<? extends PublicKey> parser) |
void |
getRawBytes(byte[] buf) |
PublicKey |
getRawPublicKey() |
PublicKey |
getRawPublicKey(BufferPublicKeyParser<? extends PublicKey> parser) |
short |
getShort() |
String |
getString() |
abstract String |
getString(Charset charset)
Reads a string using a given charset.
|
Collection<String> |
getStringList(boolean usePrependedLength) |
Collection<String> |
getStringList(boolean usePrependedLength,
Charset charset) |
List<String> |
getStringList(int count) |
List<String> |
getStringList(int count,
Charset charset) |
int |
getUByte() |
long |
getUInt() |
boolean |
isValidMessageStructure(Class<?>... fieldTypes) |
boolean |
isValidMessageStructure(Collection<Class<?>> fieldTypes) |
void |
putAndWipeBytes(byte[] 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
|
void |
putAndWipeBytes(byte[] b,
int off,
int len) |
void |
putAndWipeChars(char[] chars)
Zeroes the input array after having put the characters in the buffer - useful for sensitive information
such as passwords
|
void |
putAndWipeChars(char[] chars,
Charset charset) |
void |
putAndWipeChars(char[] chars,
int offset,
int len) |
void |
putAndWipeChars(char[] chars,
int offset,
int len,
Charset charset) |
void |
putBoolean(boolean b) |
abstract void |
putBuffer(ByteBuffer buffer) |
void |
putBuffer(Readable buffer) |
abstract int |
putBuffer(Readable buffer,
boolean expand) |
void |
putBufferedData(Object buffer)
Checks if the buffer argument is an array of bytes, a
Readable instance or a ByteBuffer
and invokes the appropriate putXXX method. |
void |
putByte(byte b) |
void |
putBytes(byte[] b) |
void |
putBytes(byte[] b,
int off,
int len) |
void |
putCertificateOptions(List<OpenSshCertificate.CertificateOption> options) |
void |
putCertificateOptions(List<OpenSshCertificate.CertificateOption> options,
Charset 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)]]]...
|
void |
putChars(char[] chars) |
void |
putChars(char[] chars,
Charset charset) |
void |
putChars(char[] chars,
int offset,
int len) |
void |
putChars(char[] chars,
int offset,
int len,
Charset charset) |
void |
putInt(long i) |
void |
putKeyPair(KeyPair kp) |
void |
putLong(long i)
Writes 64 bits
|
void |
putMPInt(BigInteger bigint) |
void |
putMPInt(byte[] mpInt) |
void |
putNameList(Collection<String> 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. |
void |
putNameList(Collection<String> names,
char separator) |
void |
putNameList(Collection<String> names,
Charset charset) |
void |
putNameList(Collection<String> names,
Charset charset,
char separator)
Adds a string that contains values separated by a delimiter
|
void |
putOptionalBufferedData(Object buffer)
Checks if the buffer argument is an array of bytes, a
Readable instance or a ByteBuffer
and invokes the appropriate putXXX method. |
void |
putPublicKey(PublicKey key) |
void |
putRawBytes(byte[] d) |
abstract void |
putRawBytes(byte[] d,
int off,
int len) |
void |
putRawPublicKey(PublicKey key) |
void |
putRawPublicKeyBytes(PublicKey key) |
void |
putShort(int i)
Writes 16 bits
|
void |
putString(String string) |
void |
putString(String string,
Charset charset) |
void |
putStringList(Collection<?> objects,
boolean prependLength)
Encodes the
toString value of each member. |
void |
putStringList(Collection<?> objects,
Charset charset,
boolean prependLength)
Encodes the
toString value of each member |
void |
putUInt(long i)
Writes 32 bits
|
byte |
rawByte(int pos) |
long |
rawUInt(int pos) |
abstract int |
rpos() |
abstract void |
rpos(int rpos) |
protected abstract int |
size() |
String |
toHex() |
String |
toString() |
abstract int |
wpos() |
abstract void |
wpos(int wpos) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
available, getRawBytes, readable
public abstract int rpos()
public abstract void rpos(int rpos)
rpos
- Set current reading positionpublic abstract int wpos()
public abstract void wpos(int wpos)
wpos
- Set current writing position - Note: if necessary, the underlying data buffer will be
increased so as to allow writing from the new positionpublic abstract int capacity()
public abstract byte[] array()
public abstract byte[] getBytesConsumed()
public byte rawByte(int pos)
pos
- A position in the raw underlying data bytesread position
.
Note: no validation is made whether the position lies within array boundariespublic long rawUInt(int pos)
pos
- A position in the raw underlying data bytesread position
. Note: no validation is made whether the position and the required extra 4
bytes lie within array boundariespublic abstract void compact()
public byte[] getCompactData()
public Buffer clear()
clear(boolean)
public abstract Buffer clear(boolean wipeData)
wipeData
- Whether to zero any previously existing datapublic boolean isValidMessageStructure(Class<?>... fieldTypes)
public boolean isValidMessageStructure(Collection<Class<?>> fieldTypes)
protected abstract void copyRawBytes(int offset, byte[] buf, int pos, int len)
public String toHex()
public void dumpHex(SimplifiedLog logger, String prefix, PropertyResolver resolver)
public void dumpHex(SimplifiedLog logger, Level level, String prefix, PropertyResolver resolver)
public int getUByte()
public byte getByte()
public short getShort()
public int getInt()
public long getUInt()
public long getLong()
public boolean getBoolean()
public String getString()
public List<String> getNameList()
public List<String> getNameList(Charset charset, char separator)
public List<OpenSshCertificate.CertificateOption> getCertificateOptions()
public List<OpenSshCertificate.CertificateOption> getCertificateOptions(Charset charset)
charset
- Charset
to use for converting bytes to charactersnull
, but possibly emptypublic Collection<String> getStringList(boolean usePrependedLength)
usePrependedLength
- 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.Collection
of the read stringsgetStringList(boolean, Charset)
public Collection<String> getStringList(boolean usePrependedLength, Charset charset)
usePrependedLength
- 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.charset
- The Charset
to use for the stringsCollection
of the read stringsgetStringList(int, Charset)
,
getAvailableStrings()
public Collection<String> getAvailableStrings()
getAvailableStrings(Charset)
public Collection<String> getAvailableStrings(Charset charset)
charset
- The Charset
to use for the stringsReadable.available()
,
getString(Charset)
public List<String> getStringList(int count)
count
- The exact number of strings to read - can be zeroList
with the specified number of stringsgetStringList(int, Charset)
public List<String> getStringList(int count, Charset charset)
count
- The exact number of strings to read - can be zerocharset
- The Charset
of the stringsList
with the specified number of stringsgetString(Charset)
public abstract String getString(Charset charset)
charset
- The Charset
to use for the string bytespublic BigInteger getMPInt()
public byte[] getMPIntAsBytes()
public byte[] getBytes()
public void getRawBytes(byte[] buf)
public PublicKey getPublicKey() throws SshException
SshException
public PublicKey getPublicKey(BufferPublicKeyParser<? extends PublicKey> parser) throws SshException
parser
- A BufferPublicKeyParser
to extract the key from the buffer - never null
PublicKey
- may be null
if the parser so decidedSshException
- If failed to extract the keygetRawPublicKey(BufferPublicKeyParser)
public PublicKey getRawPublicKey() throws SshException
SshException
public PublicKey getRawPublicKey(BufferPublicKeyParser<? extends PublicKey> parser) throws SshException
parser
- A BufferPublicKeyParser
to extract the key from the buffer - never null
PublicKey
- may be null
if the parser so decidedSshException
- If failed to extract the keypublic KeyPair getKeyPair() throws SshException
SshException
protected KeyPair extractEC(String expectedCurveName, ECParameterSpec spec) throws GeneralSecurityException
GeneralSecurityException
public int ensureAvailable(int reqLen) throws BufferException
reqLen
- Requested data in bytesBufferException
- If negative length or beyond available requestedpublic void putByte(byte b)
public void putOptionalBufferedData(Object buffer)
Readable
instance or a ByteBuffer
and invokes the appropriate putXXX
method. If null
then puts an empty byte array valuebuffer
- The buffered data object to inspectputBufferedData(Object)
public void putBufferedData(Object buffer)
Readable
instance or a ByteBuffer
and invokes the appropriate putXXX
method.buffer
- The (never null
) buffer object to putIllegalArgumentException
- If buffer is none of the supported typespublic void putBuffer(Readable buffer)
public abstract int putBuffer(Readable buffer, boolean expand)
public abstract void putBuffer(ByteBuffer buffer)
public void putShort(int i)
i
- The 16-bit valuepublic void putInt(long i)
public void putUInt(long i)
i
- The 32-bit valuepublic void putLong(long i)
i
- The 64-bit valuepublic void putBoolean(boolean b)
public void putAndWipeBytes(byte[] b)
b
- The buffer to add - OK if null
public void putAndWipeBytes(byte[] b, int off, int len)
public void putBytes(byte[] b)
public void putBytes(byte[] b, int off, int len)
public void putStringList(Collection<?> objects, boolean prependLength)
toString
value of each member.objects
- The objects to be encoded in the buffer - OK if null
/emptyprependLength
- If true
then the list is preceded by a 32-bit count of the number of members in the
listputStringList(Collection, Charset, boolean)
public void putStringList(Collection<?> objects, Charset charset, boolean prependLength)
toString
value of each memberobjects
- The objects to be encoded in the buffer - OK if null
/emptycharset
- The Charset
to use for encodingprependLength
- If true
then the list is preceded by a 32-bit count of the number of members in the
listputString(String, Charset)
public void putCertificateOptions(List<OpenSshCertificate.CertificateOption> options)
public void putCertificateOptions(List<OpenSshCertificate.CertificateOption> options, Charset charset)
options
- to write into the buffer, may be null
or empty but must not contain null
elementscharset
- The Charset
to use for string optionspublic void putNameList(Collection<String> names)
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.
names
- The name list to putpublic void putNameList(Collection<String> names, Charset charset)
public void putNameList(Collection<String> names, char separator)
public void putNameList(Collection<String> names, Charset charset, char separator)
names
- The names to setcharset
- The Charset
to use to encode the stringseparator
- The separatorpublic void putString(String string)
public void putAndWipeChars(char[] chars)
chars
- The characters to put in the buffer - may be null
/emptyputAndWipeChars(char[], Charset)
,
putChars(char[], Charset)
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 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 putMPInt(BigInteger bigint)
public void putMPInt(byte[] mpInt)
public void putRawBytes(byte[] d)
public abstract void putRawBytes(byte[] d, int off, int len)
public void putPublicKey(PublicKey key)
public void putRawPublicKey(PublicKey key)
public void putRawPublicKeyBytes(PublicKey key)
public void putKeyPair(KeyPair kp)
public Buffer ensureCapacity(int capacity)
public abstract Buffer ensureCapacity(int capacity, IntUnaryOperator growthFactor)
capacity
- The required capacitygrowthFactor
- 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 thrownprotected abstract int size()
Copyright © 2008–2024 The Apache Software Foundation. All rights reserved.