net.i2p.data.i2np

## Class BuildResponseRecord

- java.lang.Object
- - net.i2p.data.i2np.BuildResponseRecord

-     public class BuildResponseRecord
      extends Object

  Class that creates an encrypted tunnel build message record. The reply record is the same size as the request record (528 bytes). When decrypted:

       Bytes 0-31 contain the hash of bytes 32-527
       Bytes 32-526 contain random data.
       Byte 527 contains the reply.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static EncryptedBuildRecord` | `create(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyIV, long responseMessageId)` Creates a new AES-encrypted response record.
    `static EncryptedBuildRecord` | `create(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyAD, Properties options)` Creates a new ChaCha/Poly-encrypted response record (long format).
    `static ShortEncryptedBuildRecord` | `createShort(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyAD, Properties options, int slot)` Creates a new ChaCha/Poly-encrypted response record (short format).
    `static boolean` | `decrypt(EncryptedBuildRecord rec, SessionKey key, byte[] ad)` Decrypts a standard ChaCha/Poly-encrypted record.
    `static boolean` | `decrypt(EncryptedBuildRecord rec, SessionKey key, byte[] ad, int nonce)` Decrypts a short ChaCha/Poly-encrypted record.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### create

          public static EncryptedBuildRecord create(I2PAppContext ctx,
                                                    int status,
                                                    SessionKey replyKey,
                                                    byte[] replyIV,
                                                    long responseMessageId)

      Creates a new AES-encrypted response record. Create a new encrypted response. AES only for ElGamal routers.
      Parameters:
        `ctx` - the application context
        `status` - the response 0-255
        `replyKey` - the session key for reply encryption
        `replyIV` - 16 bytes IV
        `responseMessageId` - unused except for debugging
      Returns:
        a 528-byte response record

    - #### create

          public static EncryptedBuildRecord create(I2PAppContext ctx,
                                                    int status,
                                                    SessionKey replyKey,
                                                    byte[] replyAD,
                                                    Properties options)

      Creates a new ChaCha/Poly-encrypted response record (long format). Create a new encrypted response (long record). ChaCha/Poly only for ECIES routers.
      Parameters:
        `ctx` - the application context
        `status` - the response 0-255
        `replyKey` - the session key for reply encryption
        `replyAD` - 32 bytes associated data
        `options` - 511 bytes max when serialized
      Returns:
        a 528-byte response record
      Throws:
        `IllegalArgumentException` - if options too big or on encryption failure

    - #### createShort

          public static ShortEncryptedBuildRecord createShort(I2PAppContext ctx,
                                                              int status,
                                                              SessionKey replyKey,
                                                              byte[] replyAD,
                                                              Properties options,
                                                              int slot)

      Creates a new ChaCha/Poly-encrypted response record (short format). Create a new encrypted response (short record). ChaCha/Poly only for ECIES routers.
      Parameters:
        `ctx` - the application context
        `status` - the response 0-255
        `replyKey` - the session key for reply encryption
        `replyAD` - 32 bytes associated data
        `options` - 116 bytes max when serialized
        `slot` - the slot number, 0-7
      Returns:
        a 218-byte response record
      Throws:
        `IllegalArgumentException` - if options too big or on encryption failure

    - #### decrypt

          public static boolean decrypt(EncryptedBuildRecord rec,
                                        SessionKey key,
                                        byte[] ad)

      Decrypts a standard ChaCha/Poly-encrypted record. ChaCha/Poly only for ECIES routers. Handles standard (528) byte records only. Decrypts in place. Status will be rec.getData()[511]. Properties will be at rec.getData()[0].
      Parameters:
        `rec` - 528 bytes, data will be decrypted in place
        `key` - the session key for decryption
        `ad` - non-null associated data (32 bytes)
      Returns:
        true on success, false on decryption failure
      Throws:
        `IllegalArgumentException` - if record length is incorrect

    - #### decrypt

          public static boolean decrypt(EncryptedBuildRecord rec,
                                        SessionKey key,
                                        byte[] ad,
                                        int nonce)

      Decrypts a short ChaCha/Poly-encrypted record. ChaCha/Poly only for ECIES routers. Handles short (218) byte records only. Decrypts in place. Status will be rec.getData()[201]. Properties will be at rec.getData()[0].
      Parameters:
        `rec` - 218 bytes, data will be decrypted in place
        `key` - the session key for decryption
        `ad` - non-null associated data (32 bytes)
        `nonce` - the slot number, 0-7
      Returns:
        true on success, false on decryption failure
      Throws:
        `IllegalArgumentException` - if record length or nonce is invalid