java.lang.Object
net.i2p.router.crypto.ratchet.RatchetPayload

class RatchetPayloadextends Object
Ratchet payload generation and parsing.
  • Field Details

    • BLOCK_HEADER_SIZE

      public static final int BLOCK_HEADER_SIZE
      Block header size in bytes.
      See Also:
    • BLOCK_DATETIME

      private static final int BLOCK_DATETIME
      Block type of the date and time.
      See Also:
    • BLOCK_TERMINATION

      private static final int BLOCK_TERMINATION
      Block type of the termination reason.
      See Also:
    • BLOCK_OPTIONS

      private static final int BLOCK_OPTIONS
      Block type of the session options.
      See Also:
    • BLOCK_MSGNUM

      private static final int BLOCK_MSGNUM
      Block type of the message number.
      See Also:
    • BLOCK_NEXTKEY

      private static final int BLOCK_NEXTKEY
      Block type of the next ratchet key.
      See Also:
    • BLOCK_ACK

      private static final int BLOCK_ACK
      Block type of the ack.
      See Also:
    • BLOCK_ACKREQ

      private static final int BLOCK_ACKREQ
      Block type of the ack request.
      See Also:
    • BLOCK_GARLIC

      private static final int BLOCK_GARLIC
      Block type of the garlic clove.
      See Also:
    • BLOCK_PADDING

      private static final int BLOCK_PADDING
      Block type of the padding.
      See Also:
  • Constructor Details

    • RatchetPayload

      private RatchetPayload()
      Utility class with static methods only, not instantiable.
  • Method Details

    • processPayload

      public static int processPayload(I2PAppContext ctx, RatchetPayload.PayloadCallback cb, byte[] payload, int off, int length, boolean isHandshake) throws IOException, DataFormatException
      Process a ratchet payload, calling the callback for each block found.
      Parameters:
      ctx - the I2P app context
      cb - the payload callback
      payload - the frame holding the encoded blocks, read from off for length bytes
      off - the offset into the payload
      length - the number of payload bytes to scan, from off to the end of the frame
      isHandshake - true for handshake messages
      Returns:
      the number of blocks processed
      Throws:
      IOException - on I/O error
      DataFormatException - on data format error
    • writePayload

      public static int writePayload(byte[] payload, int off, List<RatchetPayload.Block> blocks)
      Write blocks to a payload buffer.
      Parameters:
      payload - writes to it starting at off
      off - the starting offset
      blocks - the blocks to write, in order, each with its own header
      Returns:
      the new offset
    • toInt4

      private static void toInt4(byte[] target, int offset, int value)
      Big endian. Same as DataHelper.toLong(int, long) for 4 bytes, but allows a negative value.
      Parameters:
      target - the buffer the 4 big endian bytes are written into
      offset - the index of the first of the 4 bytes in target
      value - the value to encode, negative values included
      Throws:
      ArrayIndexOutOfBoundsException - if offset is negative or the 4 bytes at offset run past the end of target