mirror of
https://github.com/logos-messaging/nim-sds.git
synced 2026-07-27 18:13:11 +00:00
enhance validations when deserializing message
This commit is contained in:
parent
3ef6a55257
commit
7e832a4428
@ -121,8 +121,17 @@ proc serializeMessage*(msg: SdsMessage): Result[seq[byte], ReliabilityError] =
|
||||
return err(ReliabilityError.reSerializationError)
|
||||
|
||||
proc deserializeMessage*(data: seq[byte]): Result[SdsMessage, ReliabilityError] =
|
||||
## proto3 has no required fields, so presence is validated by hand. Only the
|
||||
## identifiers are mandatory: `content`, `bloomFilter` and a zero
|
||||
## `lamportTimestamp` may legitimately be empty (e.g. periodic sync messages).
|
||||
try:
|
||||
return ok(Protobuf.decode(data, SdsMessagePB).fromPB)
|
||||
let pb = Protobuf.decode(data, SdsMessagePB)
|
||||
if pb.messageId.len == 0 or pb.channelId.len == 0:
|
||||
return err(ReliabilityError.reDeserializationError)
|
||||
for e in pb.causalHistory & pb.repairRequest:
|
||||
if e.messageId.len == 0:
|
||||
return err(ReliabilityError.reDeserializationError)
|
||||
return ok(pb.fromPB)
|
||||
except CatchableError:
|
||||
return err(ReliabilityError.reDeserializationError)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user