SenderKeyDistributionMessageWrapper.fromSerialized constructor
SenderKeyDistributionMessageWrapper.fromSerialized(
- Uint8List serialized
Implementation
SenderKeyDistributionMessageWrapper.fromSerialized(Uint8List serialized) {
try {
final messageParts =
ByteUtil.splitTwo(serialized, 1, serialized.length - 1);
final version = messageParts[0][0];
final message = messageParts[1];
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 distributionMessages =
SenderKeyDistributionMessage.fromBuffer(message);
if (!distributionMessages.hasId() ||
!distributionMessages.hasIteration() ||
!distributionMessages.hasChainKey() ||
!distributionMessages.hasSigningKey()) {
throw InvalidMessageException('Incomplete message.');
}
_serialized = serialized;
_id = distributionMessages.id;
_iteration = distributionMessages.iteration;
_chainKey = Uint8List.fromList(distributionMessages.chainKey);
_signatureKey = Curve.decodePoint(
Uint8List.fromList(distributionMessages.signingKey), 0);
} on InvalidProtocolBufferException catch (e) {
throw InvalidMessageException(e.message);
} on InvalidKeyException catch (e) {
throw InvalidMessageException(e.detailMessage);
}
}