Commit 1ccbfd97 authored by Brickner_cp's avatar Brickner_cp

DNS

parent b3807c73
...@@ -290,6 +290,9 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -290,6 +290,9 @@ namespace PcapDotNet.Packets.TestUtils
case DnsType.NInfo: case DnsType.NInfo:
return new DnsResourceDataNInfo(((Func<DataSegment>)(() => random.NextDataSegment(random.NextInt(1, 10)))).GenerateArray(10).AsReadOnly()); return new DnsResourceDataNInfo(((Func<DataSegment>)(() => random.NextDataSegment(random.NextInt(1, 10)))).GenerateArray(10).AsReadOnly());
case DnsType.RKey:
return new DnsResourceDataRKey(random.NextUShort(), random.NextByte(), random.NextEnum<DnsAlgorithm>(), random.NextDataSegment(random.NextInt(0, 100)));
default: default:
return new DnsResourceDataAnything(random.NextDataSegment(random.Next(100))); return new DnsResourceDataAnything(random.NextDataSegment(random.Next(100)));
} }
......
...@@ -5926,4 +5926,104 @@ namespace PcapDotNet.Packets.Dns ...@@ -5926,4 +5926,104 @@ namespace PcapDotNet.Packets.Dns
return new DnsResourceDataNInfo(strings.AsReadOnly()); return new DnsResourceDataNInfo(strings.AsReadOnly());
} }
} }
/// <summary>
/// Reid.
/// <pre>
/// +-----+-------+----------+-----------+
/// | bit | 0-15 | 16-23 | 24-31 |
/// +-----+-------+----------+-----------+
/// | 0 | flags | protocol | algorithm |
/// +-----+-------+----------+-----------+
/// | 32 | public key |
/// | ... | |
/// +-----+------------------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.RKey)]
public sealed class DnsResourceDataRKey : DnsResourceDataSimple, IEquatable<DnsResourceDataRKey>
{
private static class Offset
{
public const int Flags = 0;
public const int Protocol = Flags + sizeof(ushort);
public const int Algorithm = Protocol + sizeof(byte);
public const int PublicKey = Algorithm + sizeof(byte);
}
private const int ConstantPartLength = Offset.PublicKey;
public DnsResourceDataRKey(ushort flags, byte protocol, DnsAlgorithm algorithm, DataSegment publicKey)
{
Flags = flags;
Protocol = protocol;
Algorithm = algorithm;
PublicKey = publicKey;
}
/// <summary>
/// Reserved and must be zero.
/// </summary>
public ushort Flags { get; private set; }
/// <summary>
/// Must be set to 1.
/// </summary>
public byte Protocol { get; private set; }
/// <summary>
/// The key algorithm parallel to the same field for the SIG resource.
/// </summary>
public DnsAlgorithm Algorithm { get; private set; }
/// <summary>
/// The public key value.
/// </summary>
public DataSegment PublicKey { get; private set; }
public bool Equals(DnsResourceDataRKey other)
{
return other != null &&
Flags.Equals(other.Flags) &&
Protocol.Equals(other.Protocol) &&
Algorithm.Equals(other.Algorithm) &&
PublicKey.Equals(other.PublicKey);
}
public override bool Equals(DnsResourceData other)
{
return Equals(other as DnsResourceDataRKey);
}
internal DnsResourceDataRKey()
: this(0, 1, DnsAlgorithm.None, DataSegment.Empty)
{
}
internal override int GetLength()
{
return ConstantPartLength + PublicKey.Length;
}
internal override void WriteDataSimple(byte[] buffer, int offset)
{
buffer.Write(offset + Offset.Flags, Flags, Endianity.Big);
buffer.Write(offset + Offset.Protocol, Protocol);
buffer.Write(offset + Offset.Algorithm, (byte)Algorithm);
PublicKey.Write(buffer, offset + Offset.PublicKey);
}
internal override DnsResourceData CreateInstance(DataSegment data)
{
if (data.Length < ConstantPartLength)
return null;
ushort flags = data.ReadUShort(Offset.Flags, Endianity.Big);
byte protocol = data[Offset.Protocol];
DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm];
DataSegment publicKey = data.SubSegment(Offset.PublicKey, data.Length - ConstantPartLength);
return new DnsResourceDataRKey(flags, protocol, algorithm, publicKey);
}
}
} }
...@@ -386,6 +386,8 @@ ...@@ -386,6 +386,8 @@
/// <summary> /// <summary>
/// Reid. /// Reid.
/// RKEY. /// RKEY.
/// Can be used to encrypt NAPTR record.
/// Payload type: DnsResourceDataRKey.
/// </summary> /// </summary>
RKey = 57, RKey = 57,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment