mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 04:25:18 +00:00
Rename getBase64Bytes(...) → getBase64EncodedData(...)
This commit is contained in:
parent
3e7759fd07
commit
b77ac07ef5
@ -151,7 +151,6 @@ public class DatabaseFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// region Loki
|
// region Loki
|
||||||
|
|
||||||
public static LokiContactPreKeyDatabase getLokiContactPreKeyDatabase(Context context) {
|
public static LokiContactPreKeyDatabase getLokiContactPreKeyDatabase(Context context) {
|
||||||
return getInstance(context).lokiContactPreKeyDatabase;
|
return getInstance(context).lokiContactPreKeyDatabase;
|
||||||
}
|
}
|
||||||
@ -159,7 +158,6 @@ public class DatabaseFactory {
|
|||||||
public static LokiPreKeyBundleDatabase getLokiPreKeyBundleDatabase(Context context) {
|
public static LokiPreKeyBundleDatabase getLokiPreKeyBundleDatabase(Context context) {
|
||||||
return getInstance(context).lokiPreKeyBundleDatabase;
|
return getInstance(context).lokiPreKeyBundleDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
public static void upgradeRestored(Context context, SQLiteDatabase database){
|
public static void upgradeRestored(Context context, SQLiteDatabase database){
|
||||||
|
@ -25,6 +25,6 @@ fun Cursor.getString(columnName: String): String {
|
|||||||
return this.getString(this.getColumnIndexOrThrow(columnName))
|
return this.getString(this.getColumnIndexOrThrow(columnName))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Cursor.getBase64Bytes(columnName: String): ByteArray {
|
fun Cursor.getBase64EncodedData(columnName: String): ByteArray {
|
||||||
return Base64.decode(this.getString(columnName))
|
return Base64.decode(this.getString(columnName))
|
||||||
}
|
}
|
@ -14,10 +14,8 @@ import org.whispersystems.libsignal.IdentityKey
|
|||||||
import org.whispersystems.libsignal.ecc.Curve
|
import org.whispersystems.libsignal.ecc.Curve
|
||||||
import org.whispersystems.libsignal.state.PreKeyBundle
|
import org.whispersystems.libsignal.state.PreKeyBundle
|
||||||
|
|
||||||
/**
|
|
||||||
* A database for associating a `PreKeyBundle` to a contact public key.
|
|
||||||
*/
|
|
||||||
class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val tableName = "loki_pre_key_bundle_database"
|
private val tableName = "loki_pre_key_bundle_database"
|
||||||
private val pubKey = "pub_key"
|
private val pubKey = "pub_key"
|
||||||
@ -47,15 +45,15 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
|||||||
/**
|
/**
|
||||||
* Generate a `PreKeyBundle` for the given contact.
|
* Generate a `PreKeyBundle` for the given contact.
|
||||||
* This generated bundle shouldn't be stored locally since this is used to generate bundles to send to other users.
|
* This generated bundle shouldn't be stored locally since this is used to generate bundles to send to other users.
|
||||||
* @param pubKey String The hex encoded public key of the contact
|
*
|
||||||
* @return PreKeyBundle? A bundle or null if something went wrong
|
* @param pubKey String The hex encoded public key of the contact.
|
||||||
|
* @return PreKeyBundle? A pre key bundle or `null` if something went wrong.
|
||||||
*/
|
*/
|
||||||
fun generatePreKeyBundle(pubKey: String): PreKeyBundle? {
|
fun generatePreKeyBundle(pubKey: String): PreKeyBundle? {
|
||||||
// TODO: Check if we have pre keys
|
// TODO: Check if we have pre keys
|
||||||
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
|
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
|
||||||
|
|
||||||
val signedPreKey = PreKeyUtil.getActiveSignedPreKey(context)
|
val signedPreKey = PreKeyUtil.getActiveSignedPreKey(context) ?: return null
|
||||||
if (signedPreKey == null) return null
|
|
||||||
|
|
||||||
val preKeyRecord = DatabaseFactory.getLokiContactPreKeyDatabase(context).getOrCreatePreKey(pubKey)
|
val preKeyRecord = DatabaseFactory.getLokiContactPreKeyDatabase(context).getOrCreatePreKey(pubKey)
|
||||||
val registrationId = TextSecurePreferences.getLocalRegistrationId(context)
|
val registrationId = TextSecurePreferences.getLocalRegistrationId(context)
|
||||||
@ -69,8 +67,9 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the `PreKeyBundle` associated with the given contact.
|
* Get the `PreKeyBundle` associated with the given contact.
|
||||||
|
*
|
||||||
* @param pubKey String The hex encoded public key of the contact.
|
* @param pubKey String The hex encoded public key of the contact.
|
||||||
* @return PreKeyBundle? The prekey bundle or null if it doesn't exist
|
* @return PreKeyBundle? The pre key bundle or `null` if it doesn't exist.
|
||||||
*/
|
*/
|
||||||
fun getPreKeyBundle(pubKey: String): PreKeyBundle? {
|
fun getPreKeyBundle(pubKey: String): PreKeyBundle? {
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
@ -78,20 +77,21 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
|||||||
val registrationId = cursor.getInt(registrationId)
|
val registrationId = cursor.getInt(registrationId)
|
||||||
val deviceId = cursor.getInt(deviceId)
|
val deviceId = cursor.getInt(deviceId)
|
||||||
val preKeyId = cursor.getInt(preKeyId)
|
val preKeyId = cursor.getInt(preKeyId)
|
||||||
val preKey = Curve.decodePoint(cursor.getBase64Bytes(preKeyPublic), 0)
|
val preKey = Curve.decodePoint(cursor.getBase64EncodedData(preKeyPublic), 0)
|
||||||
val signedPreKeyId = cursor.getInt(signedPreKeyId)
|
val signedPreKeyId = cursor.getInt(signedPreKeyId)
|
||||||
val signedPreKey = Curve.decodePoint(cursor.getBase64Bytes(signedPreKeyPublic), 0)
|
val signedPreKey = Curve.decodePoint(cursor.getBase64EncodedData(signedPreKeyPublic), 0)
|
||||||
val signedPreKeySignature = cursor.getBase64Bytes(signedPreKeySignature)
|
val signedPreKeySignature = cursor.getBase64EncodedData(signedPreKeySignature)
|
||||||
val identityKey = IdentityKey(cursor.getBase64Bytes(identityKey), 0)
|
val identityKey = IdentityKey(cursor.getBase64EncodedData(identityKey), 0)
|
||||||
|
|
||||||
PreKeyBundle(registrationId, deviceId, preKeyId, preKey, signedPreKeyId, signedPreKey, signedPreKeySignature, identityKey)
|
PreKeyBundle(registrationId, deviceId, preKeyId, preKey, signedPreKeyId, signedPreKey, signedPreKeySignature, identityKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the `PreKeyBundle` fore the given contact.
|
* Set the `PreKeyBundle` for the given contact.
|
||||||
* @param pubKey String The hex encoded public key of the contact
|
*
|
||||||
* @param preKeyBundle PreKeyBundle The pre key bundle
|
* @param pubKey String The hex encoded public key of the contact.
|
||||||
|
* @param preKeyBundle PreKeyBundle The pre key bundle.
|
||||||
*/
|
*/
|
||||||
fun setPreKeyBundle(pubKey: String, preKeyBundle: PreKeyBundle) {
|
fun setPreKeyBundle(pubKey: String, preKeyBundle: PreKeyBundle) {
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
@ -111,7 +111,8 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the `PreKeyBundle` for the given contact.
|
* Remove the `PreKeyBundle` for the given contact.
|
||||||
* @param pubKey String The hex encoded public key of the contact
|
*
|
||||||
|
* @param pubKey String The hex encoded public key of the contact.
|
||||||
*/
|
*/
|
||||||
fun removePreKeyBundle(pubKey: String) {
|
fun removePreKeyBundle(pubKey: String) {
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
|
Loading…
Reference in New Issue
Block a user