From c04027774ffe9d4953d549432df0e18b34deda7b Mon Sep 17 00:00:00 2001 From: yet Date: Fri, 15 May 2026 17:56:13 +0400 Subject: [PATCH] refactor(noise/protocol): migrate DHState interface to Kotlin - Convert getDHName/getPublicKeyLength/getPrivateKeyLength/getSharedKeyLength from Java getters into idiomatic Kotlin `val` properties. - Tighten nullability: key buffers and DH peer parameters are non-null per the original Java @param contract; isNullPublicKey kept as a function so existing call sites (`isNullPublicKey()`) keep resolving. - Trim redundant KDoc; preserve upstream license header. Co-Authored-By: Claude Opus 4.7 --- .../noise/southernstorm/protocol/DHState.kt | 73 ++++++------------- 1 file changed, 24 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/bitchat/android/noise/southernstorm/protocol/DHState.kt b/app/src/main/java/com/bitchat/android/noise/southernstorm/protocol/DHState.kt index a01259f8..17138473 100644 --- a/app/src/main/java/com/bitchat/android/noise/southernstorm/protocol/DHState.kt +++ b/app/src/main/java/com/bitchat/android/noise/southernstorm/protocol/DHState.kt @@ -25,32 +25,16 @@ package com.bitchat.android.noise.southernstorm.protocol * Interface to a Diffie-Hellman algorithm for the Noise protocol. */ interface DHState : Destroyable { - /** - * Gets the Noise protocol name for this Diffie-Hellman algorithm. - * - * @return The algorithm name. - */ - val dHName: String? + /** The Noise protocol name for this Diffie-Hellman algorithm. */ + val dhName: String - /** - * Gets the length of public keys for this algorithm. - * - * @return The length of public keys in bytes. - */ + /** Length of public keys for this algorithm, in bytes. */ val publicKeyLength: Int - /** - * Gets the length of private keys for this algorithm. - * - * @return The length of private keys in bytes. - */ + /** Length of private keys for this algorithm, in bytes. */ val privateKeyLength: Int - /** - * Gets the length of shared keys for this algorithm. - * - * @return The length of shared keys in bytes. - */ + /** Length of shared keys for this algorithm, in bytes. */ val sharedKeyLength: Int /** @@ -60,41 +44,41 @@ interface DHState : Destroyable { /** * Gets the public key associated with this object. - * + * * @param key The buffer to copy the public key to. * @param offset The first offset in the key buffer to copy to. */ - fun getPublicKey(key: ByteArray?, offset: Int) + fun getPublicKey(key: ByteArray, offset: Int) /** * Sets the public key for this object. - * + * * @param key The buffer containing the public key. * @param offset The first offset in the buffer that contains the key. - * + * * If this object previously held a key pair, then this function * will change it into a public key only object. */ - fun setPublicKey(key: ByteArray?, offset: Int) + fun setPublicKey(key: ByteArray, offset: Int) /** * Gets the private key associated with this object. - * + * * @param key The buffer to copy the private key to. * @param offset The first offset in the key buffer to copy to. */ - fun getPrivateKey(key: ByteArray?, offset: Int) + fun getPrivateKey(key: ByteArray, offset: Int) /** * Sets the private key for this object. - * - * @param key The buffer containing the [rivate key. + * + * @param key The buffer containing the private key. * @param offset The first offset in the buffer that contains the key. - * + * * If this object previously held only a public key, then * this function will change it into a key pair. */ - fun setPrivateKey(key: ByteArray?, offset: Int) + fun setPrivateKey(key: ByteArray, offset: Int) /** * Sets this object to the null public key and clears the private key. @@ -108,47 +92,38 @@ interface DHState : Destroyable { /** * Determine if this object contains a public key. - * - * @return Returns true if this object contains a public key, - * or false if the public key has not yet been set. */ fun hasPublicKey(): Boolean /** * Determine if this object contains a private key. - * - * @return Returns true if this object contains a private key, - * or false if the private key has not yet been set. */ fun hasPrivateKey(): Boolean /** * Determine if the public key in this object is the special null value. - * - * @return Returns true if the public key is the special null value, - * or false otherwise. */ - val isNullPublicKey: Boolean + fun isNullPublicKey(): Boolean /** * Performs a Diffie-Hellman calculation with this object as the private key. - * + * * @param sharedKey Buffer to put the shared key into. * @param offset Offset of the first byte for the shared key. * @param publicDH Object that contains the public key for the calculation. - * + * * @throws IllegalArgumentException The publicDH object is not the same * type as this object, or one of the objects does not contain a valid key. */ - fun calculate(sharedKey: ByteArray?, offset: Int, publicDH: DHState?) + fun calculate(sharedKey: ByteArray, offset: Int, publicDH: DHState) /** * Copies the key values from another DH object of the same type. - * - * @param other The other DH object to copy from - * + * + * @param other The other DH object to copy from. + * * @throws IllegalStateException The other DH object does not have * the same type as this object. */ - fun copyFrom(other: DHState?) + fun copyFrom(other: DHState) }