diff --git a/lib/src/protobuf/omemo_message.dart b/lib/src/protobuf/omemo_message.dart index 95dca67..6324cf5 100644 --- a/lib/src/protobuf/omemo_message.dart +++ b/lib/src/protobuf/omemo_message.dart @@ -9,7 +9,7 @@ class OmemoMessage { var i = 0; // required uint32 n = 1; - if (data[0] != 8) { + if (data[0] != fieldId(1, fieldTypeUint32)) { throw Exception(); } var decode = decodeVarint(data, 1); @@ -17,7 +17,7 @@ class OmemoMessage { i += decode.length + 1; // required uint32 pn = 2; - if (data[i] != 16) { + if (data[i] != fieldId(2, fieldTypeUint32)) { throw Exception(); } decode = decodeVarint(data, i + 1); @@ -25,7 +25,7 @@ class OmemoMessage { i += decode.length + 1; // required bytes dh_pub = 3; - if (data[i] != ((3 << 3) | 2)) { + if (data[i] != fieldId(3, fieldTypeByteArray)) { throw Exception(); } final dhPub = data.sublist(i + 2, i + 2 + data[i + 1]); @@ -34,7 +34,7 @@ class OmemoMessage { // optional bytes ciphertext = 4; List? ciphertext; if (i < data.length) { - if (data[i] != ((4 << 3) | 2)) { + if (data[i] != fieldId(4, fieldTypeByteArray)) { throw Exception(); } diff --git a/lib/src/protobuf/protobuf.dart b/lib/src/protobuf/protobuf.dart index 3b871c0..74db070 100644 --- a/lib/src/protobuf/protobuf.dart +++ b/lib/src/protobuf/protobuf.dart @@ -4,6 +4,14 @@ const lsb7Mask = 0x7F; /// Constant for setting the MSB const msb = 1 << 7; +/// Field types +const fieldTypeUint32 = 0; +const fieldTypeByteArray = 2; + +int fieldId(int number, int type) { + return (number << 3) | type; +} + class VarintDecode { const VarintDecode(this.n, this.length);