mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 04:25:18 +00:00
Added loki functions in PreKeyUtils.
This commit is contained in:
parent
8c45a9151f
commit
a337c17960
@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.InvalidKeyIdException;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
import org.whispersystems.libsignal.state.PreKeyRecord;
|
||||
@ -89,4 +90,39 @@ public class PreKeyUtil {
|
||||
return TextSecurePreferences.getActiveSignedPreKeyId(context);
|
||||
}
|
||||
|
||||
// region - Loki
|
||||
|
||||
public synchronized static List<PreKeyRecord> generatePreKeys(Context context, int amount) {
|
||||
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);
|
||||
List<PreKeyRecord> records = new LinkedList<>();
|
||||
int preKeyIdOffset = TextSecurePreferences.getNextPreKeyId(context);
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);
|
||||
|
||||
preKeyStore.storePreKey(preKeyId, record);
|
||||
records.add(record);
|
||||
}
|
||||
|
||||
TextSecurePreferences.setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
public synchronized static void storePreKeyRecords(Context context, List<PreKeyRecord> records) {
|
||||
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);
|
||||
for (PreKeyRecord record : records) {
|
||||
preKeyStore.storePreKey(record.getId(), record);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized static PreKeyRecord loadPreKey(Context context, int preKeyId) throws InvalidKeyIdException {
|
||||
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);
|
||||
return preKeyStore.loadPreKey(preKeyId);
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user