mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Fix encoding and decoding of AUTH paket according to RFC. (#2076)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Core: Fixed issue when parsing AUTH packet with 0 length body (#2039).
|
||||
* nuget: Changed code signing and nuget certificate (**BREAKING CHANGE**).
|
||||
* TopicTemplates: Updated samples, parameter validation (#2022).
|
||||
* ManagedClient: Switch SubscribeAsync/UnsubscribeAsync to IEnumerable<string> (#2026).
|
||||
|
||||
@@ -68,12 +68,12 @@ namespace MQTTnet.Formatter.V5
|
||||
|
||||
MqttPacket DecodeAuthPacket(ArraySegment<byte> body)
|
||||
{
|
||||
ThrowIfBodyIsEmpty(body);
|
||||
|
||||
_bufferReader.SetBuffer(body.Array, body.Offset, body.Count);
|
||||
|
||||
var packet = new MqttAuthPacket();
|
||||
|
||||
// MQTT spec: The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties.
|
||||
// In this case the AUTH has a Remaining Length of 0.
|
||||
if (_bufferReader.EndOfStream)
|
||||
{
|
||||
packet.ReasonCode = MqttAuthenticateReasonCode.Success;
|
||||
|
||||
@@ -64,13 +64,20 @@ namespace MQTTnet.Formatter.V5
|
||||
|
||||
byte EncodeAuthPacket(MqttAuthPacket packet)
|
||||
{
|
||||
_bufferWriter.WriteByte((byte)packet.ReasonCode);
|
||||
|
||||
_propertiesWriter.WriteAuthenticationMethod(packet.AuthenticationMethod);
|
||||
_propertiesWriter.WriteAuthenticationData(packet.AuthenticationData);
|
||||
_propertiesWriter.WriteReasonString(packet.ReasonString);
|
||||
_propertiesWriter.WriteUserProperties(packet.UserProperties);
|
||||
|
||||
// MQTT spec: The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties.
|
||||
// In this case the AUTH has a Remaining Length of 0.
|
||||
if (packet.ReasonCode == MqttAuthenticateReasonCode.Success && _propertiesWriter.Length == 0)
|
||||
{
|
||||
return MqttBufferWriter.BuildFixedHeader(MqttControlPacketType.Auth);
|
||||
}
|
||||
|
||||
_bufferWriter.WriteByte((byte)packet.ReasonCode);
|
||||
|
||||
_propertiesWriter.WriteTo(_bufferWriter);
|
||||
_propertiesWriter.Reset();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user