Only generate a PNI key if necessary.

This commit is contained in:
Greyson Parrelli
2022-02-23 12:10:22 -05:00
parent ba08dbef5f
commit 653410cf27
4 changed files with 10 additions and 8 deletions

View File

@@ -168,11 +168,15 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
return store.containsKey(KEY_PNI_IDENTITY_PUBLIC_KEY)
}
/** Generates and saves an identity key pair for the PNI identity. Should only be done once. */
fun generatePniIdentityKey() {
/** Generates and saves an identity key pair for the PNI identity if one doesn't already exist. */
fun generatePniIdentityKeyIfNecessary() {
synchronized(this) {
if (store.containsKey(KEY_PNI_IDENTITY_PUBLIC_KEY)) {
Log.w(TAG, "Tried to generate a PNI identity, but one was already set!", Throwable())
return
}
Log.i(TAG, "Generating a new PNI identity key pair.")
require(!store.containsKey(KEY_PNI_IDENTITY_PUBLIC_KEY)) { "Already generated!" }
val key: IdentityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
store