|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Badcow DNS Library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Samuel Williams <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Badcow\DNS\Rdata; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class CaaRdata. |
|
16
|
|
|
* |
|
17
|
|
|
* SRV is defined in RFC 2782 |
|
18
|
|
|
* |
|
19
|
|
|
* @see https://tools.ietf.org/html/rfc2782 |
|
20
|
|
|
* |
|
21
|
|
|
* @author Samuel Williams <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class CAA extends CNAME |
|
24
|
|
|
{ |
|
25
|
|
|
const TYPE = 'CAA'; |
|
26
|
|
|
|
|
27
|
|
|
const MAX_FLAG = 255; |
|
28
|
|
|
|
|
29
|
|
|
const TAGS = ['issue', 'issuewild', 'iodef']; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* It is currently used to represent the critical flag |
|
33
|
|
|
* |
|
34
|
|
|
* @var int |
|
35
|
|
|
*/ |
|
36
|
|
|
private $flag; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* An ASCII string that represents the identifier of the property represented by the record. |
|
40
|
|
|
* The RFC currently defines 3 available tags: |
|
41
|
|
|
* - issue: explicity authorizes a single certificate authority to issue a certificate (any type) for the hostname. |
|
42
|
|
|
* - issuewild: explicity authorizes a single certificate authority to issue a wildcard certificate (and only wildcard) for the hostname. |
|
43
|
|
|
* - iodef: specifies a URL to which a certificate authority may report policy violations. |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
private $tag; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return int |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function getFlag(): ?int |
|
53
|
|
|
{ |
|
54
|
1 |
|
return $this->flag; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param int $flag |
|
59
|
|
|
* |
|
60
|
|
|
* @throws \InvalidArgumentException |
|
61
|
|
|
*/ |
|
62
|
2 |
|
public function setFlag(int $flag): void |
|
63
|
|
|
{ |
|
64
|
2 |
|
if ($flag < 0 || $flag > static::MAX_FLAG) { |
|
65
|
1 |
|
throw new \InvalidArgumentException('Flag must be an unsigned integer on the range [0-255]'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
$this->flag = $flag; |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return int |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function getTag(): ?string |
|
75
|
|
|
{ |
|
76
|
1 |
|
return $this->tag; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param int $tag |
|
81
|
|
|
* |
|
82
|
|
|
* @throws \InvalidArgumentException |
|
83
|
|
|
*/ |
|
84
|
2 |
|
public function setTag(string $tag): void |
|
85
|
|
|
{ |
|
86
|
2 |
|
if (!in_array($tag, static::TAGS)) { |
|
87
|
1 |
|
throw new \InvalidArgumentException('Tag can be one of this type '.implode(' ', static::TAGS)); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
$this->tag = $tag; |
|
|
|
|
|
|
91
|
1 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* {@inheritdoc} |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public function output(): string |
|
97
|
|
|
{ |
|
98
|
1 |
|
return sprintf('%s %s "%s"', |
|
99
|
1 |
|
$this->flag, |
|
100
|
1 |
|
$this->tag, |
|
101
|
1 |
|
$this->target |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.