feat: use cached keypair

This commit is contained in:
jubb 2021-02-11 18:58:38 +11:00
parent 6a8e0ae195
commit b6951f09b4

View File

@ -38,11 +38,14 @@ import org.session.libsession.utilities.TextSecurePreferences
import java.io.IOException
import java.util.*
import java.util.concurrent.atomic.AtomicReference
import kotlin.jvm.Throws
object ClosedGroupsProtocolV2 {
const val groupSizeLimit = 100
private val pendingKeyPair = AtomicReference<ECKeyPair?>(null)
sealed class Error(val description: String) : Exception() {
object NoThread : Error("Couldn't find a thread associated with the given group public key")
object NoKeyPair : Error("Couldn't find an encryption key pair associated with the given group public key.")
@ -364,7 +367,7 @@ object ClosedGroupsProtocolV2 {
return
}
// Generate the new encryption key pair
val newKeyPair = Curve.generateKeyPair()
val newKeyPair = pendingKeyPair.getAndSet(Curve.generateKeyPair()) ?: Curve.generateKeyPair()
// Distribute it
val proto = SignalServiceProtos.KeyPair.newBuilder()
proto.publicKey = ByteString.copyFrom(newKeyPair.publicKey.serialize().removing05PrefixIfNeeded())