SignalMessage.fromSerialized constructor
SignalMessage.fromSerialized(
- Uint8List serialized
Implementation
SignalMessage.fromSerialized(Uint8List serialized) {
try {
final messageParts = ByteUtil.split(
serialized, 1, serialized.length - 1 - macLength, macLength);
final version = messageParts[0].first;
final message = messageParts[1];
// ignore: unused_local_variable
final mac = messageParts[2];
if (ByteUtil.highBitsToInt(version) < CiphertextMessage.currentVersion) {
throw LegacyMessageException(
'Legacy message: $ByteUtil.highBitsToInt(version)');
}
if (ByteUtil.highBitsToInt(version) > CiphertextMessage.currentVersion) {
throw InvalidMessageException(
'Unknown version: $ByteUtil.highBitsToInt(version)');
}
final whisperMessage = signal_protos.SignalMessage.fromBuffer(message);
if (!whisperMessage.hasCiphertext() ||
!whisperMessage.hasCounter() ||
!whisperMessage.hasRatchetKey()) {
throw InvalidMessageException('Incomplete message.');
}
_serialized = serialized;
_senderRatchetKey =
Curve.decodePoint(Uint8List.fromList(whisperMessage.ratchetKey), 0);
_messageVersion = ByteUtil.highBitsToInt(version);
_counter = whisperMessage.counter;
_previousCounter = whisperMessage.previousCounter;
_ciphertext = Uint8List.fromList(whisperMessage.ciphertext);
} on InvalidProtocolBufferException catch (e) {
throw InvalidMessageException(e.toString());
} on InvalidKeyException catch (e) {
throw InvalidMessageException(e.detailMessage);
}
}