From fbb13424395cc156557fc7f747dbbf6a37de172a Mon Sep 17 00:00:00 2001 From: yet Date: Fri, 15 May 2026 17:37:47 +0400 Subject: [PATCH] Convert CipherStatePair from Java to Kotlin --- .../southernstorm/protocol/CipherStatePair.kt | 112 ++++++------------ 1 file changed, 37 insertions(+), 75 deletions(-) diff --git a/app/src/main/java/com/bitchat/android/noise/southernstorm/protocol/CipherStatePair.kt b/app/src/main/java/com/bitchat/android/noise/southernstorm/protocol/CipherStatePair.kt index 88563fce..9214b8f5 100644 --- a/app/src/main/java/com/bitchat/android/noise/southernstorm/protocol/CipherStatePair.kt +++ b/app/src/main/java/com/bitchat/android/noise/southernstorm/protocol/CipherStatePair.kt @@ -19,88 +19,50 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ - -package com.bitchat.android.noise.southernstorm.protocol; +package com.bitchat.android.noise.southernstorm.protocol /** * Class that contains a pair of CipherState objects. - * + * * CipherState pairs typically arise when HandshakeState.split() is called. + * + * @param sender The CipherState to use to send packets to the remote party. + * @param receiver The CipherState to use to receive packets from the remote party. */ -public final class CipherStatePair implements Destroyable { +class CipherStatePair( + var sender: CipherState?, + var receiver: CipherState?, +) : Destroyable { - private CipherState send; - private CipherState recv; + /** + * Destroys the receiving CipherState and retains only the sending CipherState. + * + * This function is intended for use with one-way handshake patterns. + */ + fun senderOnly() { + receiver?.destroy() + receiver = null + } - /** - * Constructs a pair of CipherState objects. - * - * @param sender The CipherState to use to send packets to the remote party. - * @param receiver The CipherState to use to receive packets from the remote party. - */ - public CipherStatePair(CipherState sender, CipherState receiver) - { - send = sender; - recv = receiver; - } + /** + * Destroys the sending CipherState and retains only the receiving CipherState. + * + * This function is intended for use with one-way handshake patterns. + */ + fun receiverOnly() { + sender?.destroy() + sender = null + } - /** - * Gets the CipherState to use to send packets to the remote party. - * - * @return The sending CipherState. - */ - public CipherState getSender() { - return send; - } - - /** - * Gets the CipherState to use to receive packets from the remote party. - * - * @return The receiving CipherState. - */ - public CipherState getReceiver() { - return recv; - } + /** + * Swaps the sender and receiver. + */ + fun swap() { + sender = receiver.also { receiver = sender } + } - /** - * Destroys the receiving CipherState and retains only the sending CipherState. - * - * This function is intended for use with one-way handshake patterns. - */ - public void senderOnly() - { - if (recv != null) { - recv.destroy(); - recv = null; - } - } - - /** - * Destroys the sending CipherState and retains only the receiving CipherState. - * - * This function is intended for use with one-way handshake patterns. - */ - public void receiverOnly() - { - if (send != null) { - send.destroy(); - send = null; - } - } - - /** - * Swaps the sender and receiver. - */ - public void swap() - { - CipherState temp = send; - send = recv; - recv = temp; - } - - @Override - public void destroy() { - senderOnly(); - receiverOnly(); - } + override fun destroy() { + senderOnly() + receiverOnly() + } }