1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Badcow DNS Library. |
7
|
|
|
* |
8
|
|
|
* (c) Samuel Williams <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Badcow\DNS\Rdata; |
15
|
|
|
|
16
|
|
|
use Badcow\DNS\Parser\Tokens; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* {@link https://tools.ietf.org/html/rfc1183}. |
20
|
|
|
*/ |
21
|
|
|
class RP implements RdataInterface |
22
|
|
|
{ |
23
|
|
|
use RdataTrait; |
24
|
|
|
|
25
|
|
|
const TYPE = 'RP'; |
26
|
|
|
const TYPE_CODE = 17; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $mailboxDomainName; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $txtDomainName; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
1 |
|
public function getMailboxDomainName(): string |
42
|
|
|
{ |
43
|
1 |
|
return $this->mailboxDomainName; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $mailboxDomainName |
48
|
|
|
*/ |
49
|
5 |
|
public function setMailboxDomainName(string $mailboxDomainName): void |
50
|
|
|
{ |
51
|
5 |
|
$this->mailboxDomainName = $mailboxDomainName; |
52
|
5 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
1 |
|
public function getTxtDomainName(): string |
58
|
|
|
{ |
59
|
1 |
|
return $this->txtDomainName; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $txtDomainName |
64
|
|
|
*/ |
65
|
5 |
|
public function setTxtDomainName(string $txtDomainName): void |
66
|
|
|
{ |
67
|
5 |
|
$this->txtDomainName = $txtDomainName; |
68
|
5 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
3 |
|
public function toText(): string |
74
|
|
|
{ |
75
|
3 |
|
return sprintf('%s %s', $this->mailboxDomainName, $this->txtDomainName); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
1 |
|
public function toWire(): string |
82
|
|
|
{ |
83
|
1 |
|
return self::encodeName($this->mailboxDomainName).self::encodeName($this->txtDomainName); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
* |
89
|
|
|
* @return RP |
90
|
|
|
*/ |
91
|
1 |
|
public static function fromText(string $text): RdataInterface |
92
|
|
|
{ |
93
|
1 |
|
$rdata = explode(Tokens::SPACE, $text); |
94
|
1 |
|
$rp = new self(); |
95
|
1 |
|
$rp->setMailboxDomainName($rdata[0]); |
96
|
1 |
|
$rp->setTxtDomainName($rdata[1]); |
97
|
|
|
|
98
|
1 |
|
return $rp; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritdoc} |
103
|
|
|
*/ |
104
|
1 |
|
public static function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): RdataInterface |
105
|
|
|
{ |
106
|
1 |
|
$rp = new self(); |
107
|
1 |
|
$rp->setMailboxDomainName(self::decodeName($rdata, $offset)); |
108
|
1 |
|
$rp->setTxtDomainName(self::decodeName($rdata, $offset)); |
109
|
|
|
|
110
|
1 |
|
return $rp; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|