refactor: Avoid using private types in public api

This commit is contained in:
Christian Pauly 2022-08-30 11:55:17 +02:00
parent ea1f340ca9
commit 3976b0f1e2
2 changed files with 20 additions and 18 deletions

View File

@ -771,7 +771,7 @@ class KeyManager {
}
final args = GenerateUploadKeysArgs(
pubkey: backupPubKey,
dbSessions: <_DbInboundGroupSessionBundle>[],
dbSessions: <DbInboundGroupSessionBundle>[],
userId: userID,
);
// we need to calculate verified beforehand, as else we pass a closure to an isolate
@ -781,7 +781,7 @@ class KeyManager {
for (final dbSession in dbSessions) {
final device =
client.getUserDeviceKeysByCurve25519Key(dbSession.senderKey);
args.dbSessions.add(_DbInboundGroupSessionBundle(
args.dbSessions.add(DbInboundGroupSessionBundle(
dbSession: dbSession,
verified: device?.verified ?? false,
));
@ -1113,12 +1113,12 @@ RoomKeys generateUploadKeysImplementation(GenerateUploadKeysArgs args) {
}
}
class _DbInboundGroupSessionBundle {
_DbInboundGroupSessionBundle(
class DbInboundGroupSessionBundle {
DbInboundGroupSessionBundle(
{required this.dbSession, required this.verified});
factory _DbInboundGroupSessionBundle.fromJson(Map<dynamic, dynamic> json) =>
_DbInboundGroupSessionBundle(
factory DbInboundGroupSessionBundle.fromJson(Map<dynamic, dynamic> json) =>
DbInboundGroupSessionBundle(
dbSession:
StoredInboundGroupSession.fromJson(Map.from(json['dbSession'])),
verified: json['verified'],
@ -1140,7 +1140,7 @@ class GenerateUploadKeysArgs {
GenerateUploadKeysArgs(
pubkey: json['pubkey'],
dbSessions: (json['dbSessions'] as Iterable)
.map((e) => _DbInboundGroupSessionBundle.fromJson(e))
.map((e) => DbInboundGroupSessionBundle.fromJson(e))
.toList(),
userId: json['userId'],
);
@ -1152,6 +1152,6 @@ class GenerateUploadKeysArgs {
};
String pubkey;
List<_DbInboundGroupSessionBundle> dbSessions;
List<DbInboundGroupSessionBundle> dbSessions;
String userId;
}

View File

@ -68,7 +68,7 @@ class SSSS {
_cache.clear();
}
static _DerivedKeys deriveKeys(Uint8List key, String name) {
static DerivedKeys deriveKeys(Uint8List key, String name) {
final zerosalt = Uint8List(8);
final prk = Hmac(sha256, zerosalt).convert(key);
final b = Uint8List(1);
@ -77,12 +77,13 @@ class SSSS {
b[0] = 2;
final hmacKey =
Hmac(sha256, prk.bytes).convert(aesKey.bytes + utf8.encode(name) + b);
return _DerivedKeys(
return DerivedKeys(
aesKey: Uint8List.fromList(aesKey.bytes),
hmacKey: Uint8List.fromList(hmacKey.bytes));
}
static Future<_Encrypted> encryptAes(String data, Uint8List key, String name,
static Future<EncryptedContent> encryptAes(
String data, Uint8List key, String name,
[String? ivStr]) async {
Uint8List iv;
if (ivStr != null) {
@ -100,14 +101,14 @@ class SSSS {
final hmac = Hmac(sha256, keys.hmacKey).convert(ciphertext);
return _Encrypted(
return EncryptedContent(
iv: base64.encode(iv),
ciphertext: base64.encode(ciphertext),
mac: base64.encode(hmac.bytes));
}
static Future<String> decryptAes(
_Encrypted data, Uint8List key, String name) async {
EncryptedContent data, Uint8List key, String name) async {
final keys = deriveKeys(key, name);
final cipher = base64decodeUnpadded(data.ciphertext);
final hmac = base64
@ -318,7 +319,7 @@ class SSSS {
throw Exception('Wrong / unknown key');
}
final enc = secretInfo.content['encrypted'][keyId];
final encryptInfo = _Encrypted(
final encryptInfo = EncryptedContent(
iv: enc['iv'], ciphertext: enc['ciphertext'], mac: enc['mac']);
final decrypted = await decryptAes(encryptInfo, key, type);
final db = client.database;
@ -604,19 +605,20 @@ class _ShareRequest {
: start = DateTime.now();
}
class _Encrypted {
class EncryptedContent {
final String iv;
final String ciphertext;
final String mac;
_Encrypted({required this.iv, required this.ciphertext, required this.mac});
EncryptedContent(
{required this.iv, required this.ciphertext, required this.mac});
}
class _DerivedKeys {
class DerivedKeys {
final Uint8List aesKey;
final Uint8List hmacKey;
_DerivedKeys({required this.aesKey, required this.hmacKey});
DerivedKeys({required this.aesKey, required this.hmacKey});
}
class OpenSSSS {