docs: Improve docstrings
This commit is contained in:
parent
3d953f0acb
commit
4ed2d3dec3
@ -1,12 +1,23 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
/// EncryptedKey is the intermediary format of a <key /> element in the OMEMO message's
|
/// EncryptedKey is the intermediary format of a <key /> element in the OMEMO message's
|
||||||
/// <keys /> header.
|
/// <keys /> header.
|
||||||
@immutable
|
@immutable
|
||||||
class EncryptedKey {
|
class EncryptedKey {
|
||||||
const EncryptedKey(this.jid, this.rid, this.value, this.kex);
|
const EncryptedKey(this.rid, this.value, this.kex);
|
||||||
final String jid;
|
|
||||||
|
/// The id of the device the key is encrypted for.
|
||||||
final int rid;
|
final int rid;
|
||||||
|
|
||||||
|
/// The base64-encoded payload.
|
||||||
final String value;
|
final String value;
|
||||||
|
|
||||||
|
/// Flag indicating whether the payload is a OMEMOKeyExchange (true) or
|
||||||
|
/// an OMEMOAuthenticatedMessage (false).
|
||||||
final bool kex;
|
final bool kex;
|
||||||
|
|
||||||
|
/// The base64-decoded payload.
|
||||||
|
List<int> get data => base64Decode(value);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import 'package:omemo_dart/src/x3dh/x3dh.dart';
|
|||||||
import 'package:synchronized/synchronized.dart';
|
import 'package:synchronized/synchronized.dart';
|
||||||
|
|
||||||
extension AppendToListOrCreateExtension<K, V> on Map<K, List<V>> {
|
extension AppendToListOrCreateExtension<K, V> on Map<K, List<V>> {
|
||||||
|
/// Create or append [value] to the list identified with key [key].
|
||||||
void appendOrCreate(K key, V value) {
|
void appendOrCreate(K key, V value) {
|
||||||
if (containsKey(key)) {
|
if (containsKey(key)) {
|
||||||
this[key]!.add(value);
|
this[key]!.add(value);
|
||||||
@ -38,6 +39,8 @@ extension AppendToListOrCreateExtension<K, V> on Map<K, List<V>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension StringFromBase64Extension on String {
|
extension StringFromBase64Extension on String {
|
||||||
|
/// Base64-decode this string. Useful for doing `someString?.fromBase64()` instead
|
||||||
|
/// of `someString != null ? base64Decode(someString) : null`.
|
||||||
List<int> fromBase64() => base64Decode(this);
|
List<int> fromBase64() => base64Decode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +258,7 @@ class OmemoManager {
|
|||||||
var processAsKex = key.kex;
|
var processAsKex = key.kex;
|
||||||
if (key.kex && _ratchetMap.containsKey(ratchetKey)) {
|
if (key.kex && _ratchetMap.containsKey(ratchetKey)) {
|
||||||
final ratchet = _ratchetMap[ratchetKey]!;
|
final ratchet = _ratchetMap[ratchetKey]!;
|
||||||
final kexMessage = OMEMOKeyExchange.fromBuffer(base64Decode(key.value));
|
final kexMessage = OMEMOKeyExchange.fromBuffer(key.data);
|
||||||
final ratchetEk = await ratchet.kex.ek.getBytes();
|
final ratchetEk = await ratchet.kex.ek.getBytes();
|
||||||
final sameEk = listsEqual(kexMessage.ek, ratchetEk);
|
final sameEk = listsEqual(kexMessage.ek, ratchetEk);
|
||||||
|
|
||||||
@ -270,7 +273,7 @@ class OmemoManager {
|
|||||||
// Process the message
|
// Process the message
|
||||||
if (processAsKex) {
|
if (processAsKex) {
|
||||||
_log.finest('Decoding message as OMEMOKeyExchange');
|
_log.finest('Decoding message as OMEMOKeyExchange');
|
||||||
final kexMessage = OMEMOKeyExchange.fromBuffer(base64Decode(key.value));
|
final kexMessage = OMEMOKeyExchange.fromBuffer(key.data);
|
||||||
|
|
||||||
// Find the correct SPK
|
// Find the correct SPK
|
||||||
final device = await getDevice();
|
final device = await getDevice();
|
||||||
@ -327,7 +330,7 @@ class OmemoManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final result = await _decryptAndVerifyHmac(
|
final result = await _decryptAndVerifyHmac(
|
||||||
stanza.payload != null ? base64Decode(stanza.payload!) : null,
|
stanza.payload?.fromBase64(),
|
||||||
keyAndHmac.get<List<int>>(),
|
keyAndHmac.get<List<int>>(),
|
||||||
);
|
);
|
||||||
if (result.isType<OmemoError>()) {
|
if (result.isType<OmemoError>()) {
|
||||||
@ -414,11 +417,9 @@ class OmemoManager {
|
|||||||
_log.finest(
|
_log.finest(
|
||||||
'Extracting OMEMOAuthenticatedMessage from OMEMOKeyExchange',
|
'Extracting OMEMOAuthenticatedMessage from OMEMOKeyExchange',
|
||||||
);
|
);
|
||||||
authMessage =
|
authMessage = OMEMOKeyExchange.fromBuffer(key.data).message;
|
||||||
OMEMOKeyExchange.fromBuffer(base64Decode(key.value)).message;
|
|
||||||
} else {
|
} else {
|
||||||
authMessage =
|
authMessage = OMEMOAuthenticatedMessage.fromBuffer(key.data);
|
||||||
OMEMOAuthenticatedMessage.fromBuffer(base64Decode(key.value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final keyAndHmac = await ratchet.ratchetDecrypt(authMessage);
|
final keyAndHmac = await ratchet.ratchetDecrypt(authMessage);
|
||||||
@ -632,7 +633,6 @@ class OmemoManager {
|
|||||||
encryptedKeys.appendOrCreate(
|
encryptedKeys.appendOrCreate(
|
||||||
jid,
|
jid,
|
||||||
EncryptedKey(
|
EncryptedKey(
|
||||||
jid,
|
|
||||||
device,
|
device,
|
||||||
base64Encode(kexMessage.writeToBuffer()),
|
base64Encode(kexMessage.writeToBuffer()),
|
||||||
true,
|
true,
|
||||||
@ -652,7 +652,6 @@ class OmemoManager {
|
|||||||
encryptedKeys.appendOrCreate(
|
encryptedKeys.appendOrCreate(
|
||||||
jid,
|
jid,
|
||||||
EncryptedKey(
|
EncryptedKey(
|
||||||
jid,
|
|
||||||
device,
|
device,
|
||||||
base64Encode(kexMessage.writeToBuffer()),
|
base64Encode(kexMessage.writeToBuffer()),
|
||||||
true,
|
true,
|
||||||
@ -663,7 +662,6 @@ class OmemoManager {
|
|||||||
encryptedKeys.appendOrCreate(
|
encryptedKeys.appendOrCreate(
|
||||||
jid,
|
jid,
|
||||||
EncryptedKey(
|
EncryptedKey(
|
||||||
jid,
|
|
||||||
device,
|
device,
|
||||||
base64Encode(authMessage.writeToBuffer()),
|
base64Encode(authMessage.writeToBuffer()),
|
||||||
false,
|
false,
|
||||||
|
Loading…
Reference in New Issue
Block a user