MailSharp / MailSharp.DNS / Records / RecordTKEY.cs
Code · 55 lines · 1425 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
49
50
51
52
53
54
55using MailSharp.DNS;
using MailSharp.DNS.Records;
using System;
/*
 * http://tools.ietf.org/rfc/rfc2930.txt
 * 
2. The TKEY Resource Record

   The TKEY resource record (RR) has the structure given below.  Its RR
   type code is 249.

      Field       Type         Comment
      -----       ----         -------
       Algorithm:   domain
       Inception:   u_int32_t
       Expiration:  u_int32_t
       Mode:        u_int16_t
       Error:       u_int16_t
       Key Size:    u_int16_t
       Key Data:    octet-stream
       Other Size:  u_int16_t
       Other Data:  octet-stream  undefined by this specification

 */

namespace MailSharp.DNS.Records;

public record RecordTKEY : DnsRecord
{
	public string Algorithm { get; }
	public uint Inception { get; }
	public uint Expiration { get; }
	public ushort Mode { get; }
	public ushort Error { get; }
	public ushort KeySize { get; }
	public byte[] KeyData { get; }
	public ushort OtherSize { get; }
	public byte[] OtherData { get; }

	public RecordTKEY(RecordReader rr) : base(rr)
	{
		Algorithm = rr.ReadDomainName();
		Inception = rr.ReadUInt32();
		Expiration = rr.ReadUInt32();
		Mode = rr.ReadUInt16();
		Error = rr.ReadUInt16();
		KeySize = rr.ReadUInt16();
		KeyData = rr.ReadBytes(KeySize);
		OtherSize = rr.ReadUInt16();
		OtherData = rr.ReadBytes(OtherSize);
	}

	public override string ToString() =>
		$"{Algorithm} {Inception} {Expiration} {Mode} {Error}";
}