feat: Track the old Signed Prekey after rotation

This commit is contained in:
2022-08-08 15:32:08 +02:00
parent 9c23721904
commit b8b6bbf800
6 changed files with 95 additions and 21 deletions

View File

@@ -1,4 +1,7 @@
import 'dart:convert';
import 'dart:math';
import 'package:cryptography/cryptography.dart';
import 'package:omemo_dart/src/keys.dart';
/// Flattens [inputs] and concatenates the elements.
List<int> concat(List<List<int>> inputs) {
@@ -39,3 +42,34 @@ List<int> generateRandomBytes(int length) {
int generateRandom32BitNumber() {
return Random.secure().nextInt(4294967295 /*pow(2, 32) - 1*/);
}
OmemoPublicKey? decodeKeyIfNotNull(Map<String, dynamic> map, String key, KeyPairType type) {
if (map[key] == null) return null;
return OmemoPublicKey.fromBytes(
base64.decode(map[key]! as String),
type,
);
}
List<int>? base64DecodeIfNotNull(Map<String, dynamic> map, String key) {
if (map[key] == null) return null;
return base64.decode(map[key]! as String);
}
String? base64EncodeIfNotNull(List<int>? bytes) {
if (bytes == null) return null;
return base64.encode(bytes);
}
OmemoKeyPair? decodeKeyPairIfNotNull(String? pk, String? sk, KeyPairType type) {
if (pk == null || sk == null) return null;
return OmemoKeyPair.fromBytes(
base64.decode(pk),
base64.decode(sk),
type,
);
}