Class Buffer<T extends Buffer<T>>

    • Field Detail

      • DEFAULT_SIZE

        public static final int DEFAULT_SIZE
        The default size for a Buffer (256 bytes)
        See Also:
        Constant Field Values
      • MAX_SIZE

        public static final int MAX_SIZE
        The maximum valid size of buffer (i.e. biggest power of two that can be represented as an int - 2^30)
        See Also:
        Constant Field Values
      • MAX_UINT64_VALUE

        public static final java.math.BigInteger MAX_UINT64_VALUE
        Maximum size of a uint64
      • data

        protected byte[] data
      • rpos

        protected int rpos
      • wpos

        protected int wpos
    • Constructor Detail

      • Buffer

        public Buffer​(Buffer<?> from)
      • Buffer

        public Buffer​(byte[] data)
      • Buffer

        public Buffer​(int size)
    • Method Detail

      • getNextPowerOf2

        protected static int getNextPowerOf2​(int i)
      • array

        public byte[] array()
      • available

        public int available()
      • clear

        public void clear()
        Resets this buffer. The object becomes ready for reuse.
      • rpos

        public int rpos()
      • rpos

        public void rpos​(int rpos)
      • wpos

        public int wpos()
      • wpos

        public void wpos​(int wpos)
      • ensureCapacity

        public void ensureCapacity​(int capacity)
      • compact

        public void compact()
        Compact this SSHPacket
      • getCompactData

        public byte[] getCompactData()
      • putBoolean

        public T putBoolean​(boolean b)
        Puts an SSH boolean value
        Parameters:
        b - the value
        Returns:
        this
      • putByte

        public T putByte​(byte b)
        Writes a single byte into this buffer
        Parameters:
        b -
        Returns:
        this
      • putBytes

        public T putBytes​(byte[] b)
        Writes Java byte-array as an SSH byte-array
        Parameters:
        b - Java byte-array
        Returns:
        this
      • putBytes

        public T putBytes​(byte[] b,
                          int off,
                          int len)
        Writes Java byte-array as an SSH byte-array
        Parameters:
        b - Java byte-array
        off - offset
        len - length
        Returns:
        this
      • putRawBytes

        public T putRawBytes​(byte[] d)
      • putRawBytes

        public T putRawBytes​(byte[] d,
                             int off,
                             int len)
      • putBuffer

        public T putBuffer​(Buffer<? extends Buffer<?>> buffer)
        Copies the contents of provided buffer into this buffer
        Parameters:
        buffer - the Buffer to copy
        Returns:
        this
      • putUInt32FromInt

        public T putUInt32FromInt​(int uint32)
        Writes a uint32 integer
        Parameters:
        uint32 -
        Returns:
        this
      • putUInt32

        public T putUInt32​(long uint32)
        Writes a uint32 integer
        Parameters:
        uint32 -
        Returns:
        this
      • putMPInt

        public T putMPInt​(java.math.BigInteger bi)
      • putUInt64

        public T putUInt64​(long uint64)
      • putUInt64

        public T putUInt64​(java.math.BigInteger uint64)
      • readString

        public java.lang.String readString​(java.nio.charset.Charset cs)
                                    throws Buffer.BufferException
        Reads an SSH string
        Parameters:
        cs - the charset to use for decoding
        Returns:
        the string as a Java String
        Throws:
        Buffer.BufferException
      • putString

        public T putString​(byte[] str)
      • putString

        public T putString​(byte[] str,
                           int offset,
                           int len)
      • putString

        public T putString​(java.lang.String string,
                           java.nio.charset.Charset cs)
      • putString

        public T putString​(java.lang.String string)
      • putSensitiveString

        public T putSensitiveString​(char[] str)
        Writes a char-array as an SSH string and then blanks it out.

        This is useful when a plaintext password needs to be sent. If str is null, an empty string is written.

        Parameters:
        str - (null-ok) the string as a character array
        Returns:
        this
      • putPublicKey

        public T putPublicKey​(java.security.PublicKey key)
      • putSignature

        public T putSignature​(java.lang.String sigFormat,
                              byte[] sigData)
      • printHex

        public java.lang.String printHex()
        Gives a readable snapshot of the buffer in hex. This is useful for debugging.
        Returns:
        snapshot of the buffer as a hex string with each octet delimited by a space
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object