MailSharp / MailSharp.DNS / Records / RecordNSEC3PARAM.cs
Code · 48 lines · 1388 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48/*
 * https://www.rfc-editor.org/rfc/rfc5155.html
 * 
 * NSEC3PARAM RDATA Wire Format

   The RDATA of the NSEC3PARAM RR is as shown below:

                        1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |   Hash Alg.   |     Flags     |          Iterations           |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |  Salt Length  |                     Salt                      /
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   
 */

using MailSharp.DNS.Records;

namespace MailSharp.DNS.Records;

public record RecordNSEC3PARAM : DnsRecord
{
	public byte HashAlgorithm { get; init; }
	public byte Flags { get; init; }
	public ushort Iterations { get; init; }
	public byte[] Salt { get; init; } = [];

	public RecordNSEC3PARAM(RecordReader rr) : base(rr)
	{
		HashAlgorithm = rr.ReadByte();
		Flags = rr.ReadByte();
		Iterations = rr.ReadUInt16();

		byte saltLength = rr.ReadByte();
		Salt = saltLength == 0 ? [] : rr.ReadBytes(saltLength);
	}

	public override string ToString()
	{
		string saltStr = Salt.Length == 0 ? "-" : Convert.ToHexString(Salt);

		// Flags wordt altijd als decimaal getal getoond (meestal 0 of 1)
		return $"{HashAlgorithm} {Flags} {Iterations} {saltStr}";
	}

}