Interface NoiseTransportReader
- All Known Subinterfaces:
NoiseTransport
A Noise transport reader decrypts Noise transport messages. In the terminology of the Noise
Protocol Framework specification, a NoiseTransportReader instance encapsulates a "cipher state" produced by
"splitting" a NoiseHandshake instance.
Noise transport reader instances are stateful and are not thread-safe.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionintgetPlaintextLength(int ciphertextLength) Returns the length of the plaintext resulting from the decryption of a ciphertext of the given size.byte[]readMessage(byte[] ciphertext) Decrypts a Noise transport message, returning a new byte array sized exactly to contain the resulting plaintext.intreadMessage(byte[] ciphertext, int ciphertextOffset, int ciphertextLength, byte[] plaintext, int plaintextOffset) Decrypts a Noise transport message and writes the resulting plaintext into the given byte array.readMessage(ByteBuffer ciphertext) Decrypts a Noise transport message and verifies its AEAD tag.intreadMessage(ByteBuffer ciphertext, ByteBuffer plaintext) Decrypts a Noise transport message and verifies its AEAD tag.voidSets the decryption key used by this reader to a new pseudo-random key derived from the current key.
-
Method Details
-
getPlaintextLength
int getPlaintextLength(int ciphertextLength) Returns the length of the plaintext resulting from the decryption of a ciphertext of the given size.- Parameters:
ciphertextLength- the length of a ciphertext- Returns:
- the length of the plaintext resulting from the decryption of a ciphertext of the given size
- Throws:
IllegalArgumentException- if the given ciphertext length is too small to contain a valid AEAD tag
-
readMessage
Decrypts a Noise transport message and verifies its AEAD tag. This method returns a newByteBuffersized exactly to contain the resulting plaintext. The returned buffer's position will be zero, and its limit and capacity will be equal to the plaintext length.All
ciphertext.remaining()bytes starting atciphertext.position()are processed. Upon return, the ciphertext buffer's position will be equal to its limit; its limit will not have changed.- Parameters:
ciphertext- the ciphertext of the Noise transport message to decrypt- Returns:
- a
ByteBuffercontaining the resulting plaintext - Throws:
AEADBadTagException- if the AEAD tag in the given ciphertext does not match the calculated valueIllegalArgumentException- if the given ciphertext is too short to contain a valid AEAD tag or if it is larger than the maximum allowed Noise transport message size- See Also:
-
readMessage
int readMessage(ByteBuffer ciphertext, ByteBuffer plaintext) throws ShortBufferException, AEADBadTagException Decrypts a Noise transport message and verifies its AEAD tag. This method writes the resulting plaintext into the givenplaintextbuffer. Callers are responsible for ensuring that the given plaintext buffer has enough remaining capacity to hold the resulting plaintext.All
ciphertext.remaining()bytes starting atciphertext.position()are processed. Upon return, the ciphertext buffer's position will be equal to its limit; its limit will not have changed. The plaintext buffer's position will have advanced by n, where n is the value returned by this method; the plaintext buffer's limit will not have changed.- Parameters:
ciphertext- the ciphertext of the Noise transport message to decryptplaintext- the buffer into which to write the resulting plaintext- Returns:
- the number of bytes written into the
plaintextbuffer - Throws:
AEADBadTagException- if the AEAD tag in the given ciphertext does not match the calculated valueIllegalArgumentException- if the given ciphertext is too short to contain a valid AEAD tag or if it is larger than the maximum allowed Noise transport message sizeShortBufferException- if the given plaintext buffer does not have enough remaining capacity to hold the resulting plaintext- See Also:
-
readMessage
Decrypts a Noise transport message, returning a new byte array sized exactly to contain the resulting plaintext.- Parameters:
ciphertext- the ciphertext of the Noise transport message to decrypt- Returns:
- a new byte array containing the resulting plaintext
- Throws:
AEADBadTagException- if the AEAD tag in the given ciphertext does not match the calculated AEAD tagIllegalArgumentException- if the given ciphertext is too short to contain a valid AEAD tag or if it is larger than the maximum allowed Noise transport message size
-
readMessage
int readMessage(byte[] ciphertext, int ciphertextOffset, int ciphertextLength, byte[] plaintext, int plaintextOffset) throws ShortBufferException, AEADBadTagException Decrypts a Noise transport message and writes the resulting plaintext into the given byte array. Note thatciphertextandplaintextmay refer to the same byte array, allowing for in-place decryption.- Parameters:
ciphertext- the ciphertext of the Noise transport message to decryptciphertextOffset- the position withinciphertextat which to begin reading the ciphertext and AEAD tagciphertextLength- the length of the ciphertext and AEAD tag withinciphertextplaintext- a byte array into which to write the decrypted plaintextplaintextOffset- the offset withinplaintextwhere the plaintext begins- Returns:
- the number of bytes written to
plaintext - Throws:
AEADBadTagException- if the AEAD tag in the given ciphertext does not match the calculated valueShortBufferException- ifplaintextis not long enough (after its offset) to contain the resulting plaintextIllegalArgumentException- if the given ciphertext is too short to contain a valid AEAD tag or if it is larger than the maximum allowed Noise transport message size
-
rekeyReader
void rekeyReader()Sets the decryption key used by this reader to a new pseudo-random key derived from the current key. This operation must be coordinated with the sending party, otherwise messages from the sending party will be unintelligible and decrypting future messages will fail.
-