Completed
Branch Version3 (b9f3d9)
by Sam
02:31
created

Factory::NS()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
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\ParseException;
17
use Badcow\DNS\Parser\Tokens;
18
use PhpIP\IPBlock;
19
20
class Factory
21
{
22
    /**
23
     * Creates a new RData object from a name.
24
     *
25
     * @param string $name
26
     *
27
     * @throws UnsupportedTypeException
28
     *
29
     * @return RdataInterface
30
     */
31 1
    public static function newRdataFromName(string $name): RdataInterface
32
    {
33 1
        if (!self::isTypeImplemented($name)) {
34 1
            throw new UnsupportedTypeException($name);
35
        }
36
37 1
        $className = self::getRdataClassName($name);
38
39 1
        return new $className();
40
    }
41
42
    /**
43
     * @param int $id
44
     *
45
     * @return RdataInterface
46
     *
47
     * @throws UnsupportedTypeException
48
     */
49
    public static function newRdataFromId(int $id): RdataInterface
50
    {
51
        return self::newRdataFromName(TypeCodes::getName($id));
52
    }
53
54
    /**
55
     * @param string $name
56
     *
57
     * @return bool
58
     */
59 18
    public static function isTypeImplemented(string $name): bool
60
    {
61 18
        return class_exists(self::getRdataClassName($name));
62
    }
63
64
    /**
65
     * @param int $typeCode
66
     *
67
     * @return bool
68
     */
69 1
    public static function isTypeCodeImplemented(int $typeCode): bool
70
    {
71
        try {
72 1
            return self::isTypeImplemented(TypeCodes::getName($typeCode));
73 1
        } catch (UnsupportedTypeException $e) {
74 1
            return false;
75
        }
76
    }
77
78
    /**
79
     * @param string $type
80
     * @param string $text
81
     *
82
     * @return RdataInterface
83
     *
84
     * @throws ParseException
85
     * @throws UnsupportedTypeException
86
     */
87 17
    public static function textToRdataType(string $type, string $text): RdataInterface
88
    {
89 17
        if (1 === preg_match('/^TYPE(\d+)$/', $type, $matches)) {
90 1
            $typeCode = (int) $matches[1];
91 1
            if (self::isTypeCodeImplemented($typeCode)) {
92 1
                $type = TypeCodes::getName($typeCode);
93
            } else {
94 1
                $rdata = UnknownType::fromText($text);
95 1
                $rdata->setTypeCode($typeCode);
96
97 1
                return $rdata;
98
            }
99
        }
100
101 17
        if (!self::isTypeImplemented($type)) {
102 1
            return new PolymorphicRdata($type, $text);
103
        }
104
105 16
        if (1 === preg_match('/^\\\#\s+(\d+)(\s[a-f0-9\s]+)?$/i', $text, $matches)) {
106 1
            if ('0' === $matches[1]) {
107
                $className = self::getRdataClassName($type);
108
109
                return new $className();
110
            }
111 1
            $wireFormat = hex2bin(str_replace(Tokens::SPACE, '', $matches[2]));
112
113
            /** @var callable $callable */
114 1
            $callable = self::getRdataClassName($type).'::fromWire';
115
116 1
            return call_user_func($callable, $wireFormat);
117
        }
118
119
        /** @var callable $callable */
120 15
        $callable = self::getRdataClassName($type).'::fromText';
121
122 15
        return call_user_func($callable, $text);
123
    }
124
125
    /**
126
     * Get the fully qualified class name of the RData class for $type.
127
     *
128
     * @param string $type
129
     *
130
     * @return string
131
     */
132 18
    public static function getRdataClassName(string $type): string
133
    {
134 18
        return __NAMESPACE__.'\\'.strtoupper($type);
135
    }
136
137
    /**
138
     * Create a new AAAA R-Data object.
139
     *
140
     * @param string $address
141
     *
142
     * @return AAAA
143
     */
144 12
    public static function AAAA(string $address): AAAA
145
    {
146 12
        $rdata = new AAAA();
147 12
        $rdata->setAddress($address);
148
149 12
        return $rdata;
150
    }
151
152
    /**
153
     * Create a new A R-Data object.
154
     *
155
     * @param string $address
156
     *
157
     * @return A
158
     */
159 13
    public static function A(string $address): A
160
    {
161 13
        $rdata = new A();
162 13
        $rdata->setAddress($address);
163
164 13
        return $rdata;
165
    }
166
167
    /**
168
     * Create a new CNAME object.
169
     *
170
     * @param string $cname
171
     *
172
     * @return CNAME
173
     */
174 9
    public static function CNAME(string $cname): CNAME
175
    {
176 9
        $rdata = new CNAME();
177 9
        $rdata->setTarget($cname);
178
179 9
        return $rdata;
180
    }
181
182
    /**
183
     * @param string $cpu
184
     * @param string $os
185
     *
186
     * @return HINFO
187
     */
188 9
    public static function HINFO(string $cpu, string $os): HINFO
189
    {
190 9
        $rdata = new HINFO();
191 9
        $rdata->setCpu($cpu);
192 9
        $rdata->setOs($os);
193
194 9
        return $rdata;
195
    }
196
197
    /**
198
     * @param int    $preference
199
     * @param string $exchange
200
     *
201
     * @return MX
202
     */
203 11
    public static function MX(int $preference, string $exchange): MX
204
    {
205 11
        $rdata = new MX();
206 11
        $rdata->setPreference($preference);
207 11
        $rdata->setExchange($exchange);
208
209 11
        return $rdata;
210
    }
211
212
    /**
213
     * @param string $mname
214
     * @param string $rname
215
     * @param int    $serial
216
     * @param int    $refresh
217
     * @param int    $retry
218
     * @param int    $expire
219
     * @param int    $minimum
220
     *
221
     * @return SOA
222
     */
223 14
    public static function SOA(string $mname, string $rname, int $serial, int $refresh, int $retry, int $expire, int $minimum): SOA
224
    {
225 14
        $rdata = new SOA();
226 14
        $rdata->setMname($mname);
227 14
        $rdata->setRname($rname);
228 14
        $rdata->setSerial($serial);
229 14
        $rdata->setRefresh($refresh);
230 14
        $rdata->setRetry($retry);
231 14
        $rdata->setExpire($expire);
232 14
        $rdata->setMinimum($minimum);
233
234 14
        return $rdata;
235
    }
236
237
    /**
238
     * @param string $nsdname
239
     *
240
     * @return NS
241
     */
242 13
    public static function NS(string $nsdname): NS
243
    {
244 13
        $rdata = new NS();
245 13
        $rdata->setTarget($nsdname);
246
247 13
        return $rdata;
248
    }
249
250
    /**
251
     * @param string $text
252
     *
253
     * @return TXT
254
     */
255 10
    public static function TXT(string $text): TXT
256
    {
257 10
        $rdata = new TXT();
258 10
        $rdata->setText($text);
259
260 10
        return $rdata;
261
    }
262
263
    /**
264
     * @param string $target
265
     *
266
     * @return DNAME
267
     */
268 9
    public static function DNAME(string $target): DNAME
269
    {
270 9
        $rdata = new DNAME();
271 9
        $rdata->setTarget($target);
272
273 9
        return $rdata;
274
    }
275
276
    /**
277
     * @param float $lat
278
     * @param float $lon
279
     * @param float $alt
280
     * @param float $size
281
     * @param float $hp
282
     * @param float $vp
283
     *
284
     * @return LOC
285
     */
286 10
    public static function LOC(float $lat, float $lon, $alt = 0.0, $size = 1.0, $hp = 10000.0, $vp = 10.0): LOC
287
    {
288 10
        $loc = new LOC();
289 10
        $loc->setLatitude($lat);
290 10
        $loc->setLongitude($lon);
291 10
        $loc->setAltitude($alt);
292 10
        $loc->setSize($size);
293 10
        $loc->setHorizontalPrecision($hp);
294 10
        $loc->setVerticalPrecision($vp);
295
296 10
        return $loc;
297
    }
298
299
    /**
300
     * @param string $target
301
     *
302
     * @return PTR
303
     */
304 2
    public static function PTR(string $target): PTR
305
    {
306 2
        $ptr = new PTR();
307 2
        $ptr->setTarget($target);
308
309 2
        return $ptr;
310
    }
311
312
    /**
313
     * @param int    $flags
314
     * @param int    $algorithm
315
     * @param string $publicKey
316
     *
317
     * @return DNSKEY
318
     */
319 1
    public static function DNSKEY(int $flags, int $algorithm, string $publicKey): DNSKEY
320
    {
321 1
        $rdata = new DNSKEY();
322 1
        $rdata->setFlags($flags);
323 1
        $rdata->setAlgorithm($algorithm);
324 1
        $rdata->setPublicKey($publicKey);
325
326 1
        return $rdata;
327
    }
328
329
    /**
330
     * @param int    $keyTag
331
     * @param int    $algorithm
332
     * @param string $digest
333
     * @param int    $digestType
334
     *
335
     * @return DS
336
     */
337 1
    public static function DS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DS
338
    {
339 1
        $rdata = new DS();
340 1
        $rdata->setKeyTag($keyTag);
341 1
        $rdata->setAlgorithm($algorithm);
342 1
        $rdata->setDigest($digest);
343 1
        $rdata->setDigestType($digestType);
344
345 1
        return $rdata;
346
    }
347
348
    /**
349
     * @param string $nextDomainName
350
     * @param array  $types
351
     *
352
     * @return NSEC
353
     */
354 1
    public static function NSEC(string $nextDomainName, array $types): NSEC
355
    {
356 1
        $rdata = new NSEC();
357 1
        $rdata->setNextDomainName($nextDomainName);
358 1
        array_map([$rdata, 'addType'], $types);
359
360 1
        return $rdata;
361
    }
362
363
    /**
364
     * @param string    $typeCovered
365
     * @param int       $algorithm
366
     * @param int       $labels
367
     * @param int       $originalTtl
368
     * @param \DateTime $signatureExpiration
369
     * @param \DateTime $signatureInception
370
     * @param int       $keyTag
371
     * @param string    $signersName
372
     * @param string    $signature
373
     *
374
     * @return RRSIG
375
     */
376 1
    public static function RRSIG(string $typeCovered, int $algorithm, int $labels, int $originalTtl,
377
                                    \DateTime $signatureExpiration, \DateTime $signatureInception, int $keyTag,
378
                                    string $signersName, string $signature): RRSIG
379
    {
380 1
        $rrsig = new RRSIG();
381 1
        $rrsig->setTypeCovered($typeCovered);
382 1
        $rrsig->setAlgorithm($algorithm);
383 1
        $rrsig->setLabels($labels);
384 1
        $rrsig->setOriginalTtl($originalTtl);
385 1
        $rrsig->setSignatureExpiration($signatureExpiration);
386 1
        $rrsig->setSignatureInception($signatureInception);
387 1
        $rrsig->setKeyTag($keyTag);
388 1
        $rrsig->setSignersName($signersName);
389 1
        $rrsig->setSignature($signature);
390
391 1
        return $rrsig;
392
    }
393
394
    /**
395
     * @param int    $priority
396
     * @param int    $weight
397
     * @param int    $port
398
     * @param string $target
399
     *
400
     * @return SRV
401
     */
402 1
    public static function SRV(int $priority, int $weight, int $port, string $target): SRV
403
    {
404 1
        $rdata = new SRV();
405 1
        $rdata->setPriority($priority);
406 1
        $rdata->setWeight($weight);
407 1
        $rdata->setPort($port);
408 1
        $rdata->setTarget($target);
409
410 1
        return $rdata;
411
    }
412
413
    /**
414
     * @param IPBlock[] $includedRanges
415
     * @param IPBlock[] $excludedRanges
416
     *
417
     * @return APL
418
     */
419 2
    public static function APL(array $includedRanges = [], array $excludedRanges = []): APL
420
    {
421 2
        $rdata = new APL();
422
423 2
        foreach ($includedRanges as $ipBlock) {
424 2
            $rdata->addAddressRange($ipBlock, true);
425
        }
426
427 2
        foreach ($excludedRanges as $ipBlock) {
428 2
            $rdata->addAddressRange($ipBlock, false);
429
        }
430
431 2
        return $rdata;
432
    }
433
434
    /**
435
     * @param int    $flag
436
     * @param string $tag
437
     * @param string $value
438
     *
439
     * @return CAA
440
     */
441 1
    public static function CAA(int $flag, string $tag, string $value): CAA
442
    {
443 1
        $rdata = new CAA();
444 1
        $rdata->setFlag($flag);
445 1
        $rdata->setTag($tag);
446 1
        $rdata->setValue($value);
447
448 1
        return $rdata;
449
    }
450
451
    /**
452
     * @param int    $subType
453
     * @param string $hostname
454
     *
455
     * @return AFSDB
456
     */
457
    public static function AFSDB(int $subType, string $hostname): AFSDB
458
    {
459
        $afsdb = new AFSDB();
460
        $afsdb->setSubType($subType);
461
        $afsdb->setHostname($hostname);
462
463
        return $afsdb;
464
    }
465
466
    /**
467
     * @param int    $flags
468
     * @param int    $algorithm
469
     * @param string $publicKey
470
     *
471
     * @return CDNSKEY
472
     */
473
    public static function CDNSKEY(int $flags, int $algorithm, string $publicKey): CDNSKEY
474
    {
475
        $cdnskey = new CDNSKEY();
476
        $cdnskey->setFlags($flags);
477
        $cdnskey->setAlgorithm($algorithm);
478
        $cdnskey->setPublicKey($publicKey);
479
480
        return $cdnskey;
481
    }
482
483
    /**
484
     * @param int    $keyTag
485
     * @param int    $algorithm
486
     * @param string $digest
487
     * @param int    $digestType
488
     *
489
     * @return CDS
490
     */
491
    public static function CDS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): CDS
492
    {
493
        $cds = new CDS();
494
        $cds->setKeyTag($keyTag);
495
        $cds->setAlgorithm($algorithm);
496
        $cds->setDigest($digest);
497
        $cds->setDigestType($digestType);
498
499
        return $cds;
500
    }
501
502
    /**
503
     * @param int|string $certificateType
504
     * @param int        $keyTag
505
     * @param int        $algorithm
506
     * @param string     $certificate
507
     *
508
     * @return CERT
509
     */
510 1
    public static function CERT($certificateType, int $keyTag, int $algorithm, string $certificate): CERT
511
    {
512 1
        $cert = new CERT();
513 1
        $cert->setCertificateType($certificateType);
514 1
        $cert->setKeyTag($keyTag);
515 1
        $cert->setAlgorithm($algorithm);
516 1
        $cert->setCertificate($certificate);
517
518 1
        return $cert;
519
    }
520
521 1
    public static function CSYNC(int $soaSerial, int $flags, array $types): CSYNC
522
    {
523 1
        $csync = new CSYNC();
524 1
        $csync->setSoaSerial($soaSerial);
525 1
        $csync->setFlags($flags);
526 1
        array_map([$csync, 'addType'], $types);
527
528 1
        return $csync;
529
    }
530
531
    /**
532
     * @param string|null $digest         Set to &null if the $identifier and $fqdn are known
533
     * @param int         $identifierType 16-bit integer
534
     * @param string|null $identifier     This is ignored if $digest is not &null
535
     * @param string|null $fqdn           This is ignored if $digest is not &null
536
     *
537
     * @return DHCID
538
     */
539 3
    public static function DHCID(?string $digest, int $identifierType, ?string $identifier = null, ?string $fqdn = null): DHCID
540
    {
541 3
        $dhcid = new DHCID();
542 3
        if (null !== $digest) {
543
            $dhcid->setIdentifierType($identifierType);
544
            $dhcid->setDigest($digest);
545
546
            return $dhcid;
547
        }
548
549 3
        if (null === $identifier || null === $fqdn) {
550
            throw new \InvalidArgumentException('Identifier and FQDN cannot be null if digest is null.');
551
        }
552
553 3
        $dhcid->setIdentifier($identifierType, $identifier);
554 3
        $dhcid->setFqdn($fqdn);
555
556 3
        return $dhcid;
557
    }
558
559
    /**
560
     * @param int    $keyTag
561
     * @param int    $algorithm
562
     * @param string $digest
563
     * @param int    $digestType
564
     *
565
     * @return DLV
566
     */
567
    public static function DLV(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DLV
568
    {
569
        $rdata = new DLV();
570
        $rdata->setKeyTag($keyTag);
571
        $rdata->setAlgorithm($algorithm);
572
        $rdata->setDigest($digest);
573
        $rdata->setDigestType($digestType);
574
575
        return $rdata;
576
    }
577
578
    /**
579
     * @param int      $publicKeyAlgorithm
580
     * @param string   $hostIdentityTag
581
     * @param string   $publicKey
582
     * @param string[] $rendezvousServers
583
     *
584
     * @return HIP
585
     */
586 1
    public static function HIP(int $publicKeyAlgorithm, string $hostIdentityTag, string $publicKey, array $rendezvousServers): HIP
587
    {
588 1
        $hip = new HIP();
589 1
        $hip->setPublicKeyAlgorithm($publicKeyAlgorithm);
590 1
        $hip->setHostIdentityTag($hostIdentityTag);
591 1
        $hip->setPublicKey($publicKey);
592 1
        array_map([$hip, 'addRendezvousServer'], $rendezvousServers);
593
594 1
        return $hip;
595
    }
596
597
    /**
598
     * @param int         $precedence an 8-bit unsigned integer
599
     * @param string|null $gateway    either &null for no gateway, a fully qualified domain name, or an IPv4 or IPv6 address
600
     * @param int         $algorithm  either IPSECKEY::ALGORITHM_NONE, IPSECKEY::ALGORITHM_DSA, IPSECKEY::ALGORITHM_RSA, or IPSECKEY::ALGORITHM_ECDSA
601
     * @param string|null $publicKey  base64 encoded public key
602
     *
603
     * @return IPSECKEY
604
     */
605 6
    public static function IPSECKEY(int $precedence, ?string $gateway, int $algorithm = 0, ?string $publicKey = null): IPSECKEY
606
    {
607 6
        $ipseckey = new IPSECKEY();
608 6
        $ipseckey->setPrecedence($precedence);
609 6
        $ipseckey->setGateway($gateway);
610 6
        $ipseckey->setPublicKey($algorithm, $publicKey);
611
612 6
        return $ipseckey;
613
    }
614
615
    /**
616
     * @param int    $flags
617
     * @param int    $protocol
618
     * @param int    $algorithm
619
     * @param string $publicKey
620
     *
621
     * @return KEY
622
     */
623
    public static function KEY(int $flags, int $protocol, int $algorithm, string $publicKey): KEY
624
    {
625
        $key = new KEY();
626
        $key->setFlags($flags);
627
        $key->setProtocol($protocol);
628
        $key->setAlgorithm($algorithm);
629
        $key->setPublicKey($publicKey);
630
631
        return $key;
632
    }
633
634
    /**
635
     * @param int    $preference
636
     * @param string $exchanger
637
     *
638
     * @return KX
639
     */
640
    public static function KX(int $preference, string $exchanger): KX
641
    {
642
        $kx = new KX();
643
        $kx->setPreference($preference);
644
        $kx->setExchanger($exchanger);
645
646
        return $kx;
647
    }
648
649
    /**
650
     * @param int    $order
651
     * @param int    $preference
652
     * @param string $flags
653
     * @param string $services
654
     * @param string $regexp
655
     * @param string $replacement
656
     *
657
     * @return NAPTR
658
     */
659 2
    public static function NAPTR(int $order, int $preference, string $flags, string $services, string $regexp, string $replacement): NAPTR
660
    {
661 2
        $naptr = new NAPTR();
662 2
        $naptr->setOrder($order);
663 2
        $naptr->setPreference($preference);
664 2
        $naptr->setFlags($flags);
665 2
        $naptr->setServices($services);
666 2
        $naptr->setRegexp($regexp);
667 2
        $naptr->setReplacement($replacement);
668
669 2
        return $naptr;
670
    }
671
672
    /**
673
     * @param int    $hashAlgorithm
674
     * @param bool   $unsignedDelegationsCovered
675
     * @param int    $iterations
676
     * @param string $salt
677
     * @param string $nextHashedOwnerName
678
     * @param array  $types
679
     *
680
     * @return NSEC3
681
     */
682 1
    public static function NSEC3(int $hashAlgorithm, bool $unsignedDelegationsCovered, int $iterations, string $salt, string $nextHashedOwnerName, array $types): NSEC3
683
    {
684 1
        $nsec3 = new NSEC3();
685 1
        $nsec3->setHashAlgorithm($hashAlgorithm);
686 1
        $nsec3->setUnsignedDelegationsCovered($unsignedDelegationsCovered);
687 1
        $nsec3->setIterations($iterations);
688 1
        $nsec3->setSalt($salt);
689 1
        $nsec3->setNextHashedOwnerName($nextHashedOwnerName);
690 1
        array_map([$nsec3, 'addType'], $types);
691
692 1
        return $nsec3;
693
    }
694
695
    /**
696
     * @param int    $hashAlgorithm
697
     * @param int    $flags
698
     * @param int    $iterations
699
     * @param string $salt
700
     *
701
     * @return NSEC3PARAM
702
     */
703 1
    public static function NSEC3PARAM(int $hashAlgorithm, int $flags, int $iterations, string $salt): NSEC3PARAM
704
    {
705 1
        $nsec3param = new NSEC3PARAM();
706 1
        $nsec3param->setHashAlgorithm($hashAlgorithm);
707 1
        $nsec3param->setFlags($flags);
708 1
        $nsec3param->setIterations($iterations);
709 1
        $nsec3param->setSalt($salt);
710
711 1
        return $nsec3param;
712
    }
713
714
    public static function RP(string $mboxDomain, string $txtDomain): RP
715
    {
716
        $rp = new RP();
717
        $rp->setMailboxDomainName($mboxDomain);
718
        $rp->setTxtDomainName($txtDomain);
719
720
        return $rp;
721
    }
722
723
    /**
724
     * @param string    $typeCovered
725
     * @param int       $algorithm
726
     * @param int       $labels
727
     * @param int       $originalTtl
728
     * @param \DateTime $signatureExpiration
729
     * @param \DateTime $signatureInception
730
     * @param int       $keyTag
731
     * @param string    $signersName
732
     * @param string    $signature
733
     *
734
     * @return SIG
735
     */
736
    public static function SIG(string $typeCovered, int $algorithm, int $labels, int $originalTtl,
737
                                 \DateTime $signatureExpiration, \DateTime $signatureInception, int $keyTag,
738
                                 string $signersName, string $signature): SIG
739
    {
740
        $sig = new SIG();
741
        $sig->setTypeCovered($typeCovered);
742
        $sig->setAlgorithm($algorithm);
743
        $sig->setLabels($labels);
744
        $sig->setOriginalTtl($originalTtl);
745
        $sig->setSignatureExpiration($signatureExpiration);
746
        $sig->setSignatureInception($signatureInception);
747
        $sig->setKeyTag($keyTag);
748
        $sig->setSignersName($signersName);
749
        $sig->setSignature($signature);
750
751
        return $sig;
752
    }
753
754
    /**
755
     * @param int    $algorithm
756
     * @param int    $fpType
757
     * @param string $fingerprint
758
     *
759
     * @return SSHFP
760
     */
761 8
    public static function SSHFP(int $algorithm, int $fpType, string $fingerprint): SSHFP
762
    {
763 8
        $sshfp = new SSHFP();
764 8
        $sshfp->setAlgorithm($algorithm);
765 6
        $sshfp->setFingerprintType($fpType);
766 4
        $sshfp->setFingerprint($fingerprint);
767
768 3
        return $sshfp;
769
    }
770
771
    /**
772
     * @param int    $keyTag
773
     * @param int    $algorithm
774
     * @param string $digest
775
     * @param int    $digestType
776
     *
777
     * @return TA
778
     */
779
    public static function TA(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): TA
780
    {
781
        $ta = new TA();
782
        $ta->setKeyTag($keyTag);
783
        $ta->setAlgorithm($algorithm);
784
        $ta->setDigest($digest);
785
        $ta->setDigestType($digestType);
786
787
        return $ta;
788
    }
789
790
    /**
791
     * @param string    $algorithm
792
     * @param \DateTime $inception
793
     * @param \DateTime $expiration
794
     * @param int       $mode
795
     * @param int       $error
796
     * @param string    $keyData    binary string
797
     * @param string    $otherData  binary string
798
     *
799
     * @return TKEY
800
     */
801 1
    public static function TKEY(string $algorithm, \DateTime $inception, \DateTime $expiration, int $mode, int $error, string $keyData, string $otherData = ''): TKEY
802
    {
803 1
        $tkey = new TKEY();
804 1
        $tkey->setAlgorithm($algorithm);
805 1
        $tkey->setInception($inception);
806 1
        $tkey->setExpiration($expiration);
807 1
        $tkey->setMode($mode);
808 1
        $tkey->setError($error);
809 1
        $tkey->setKeyData($keyData);
810 1
        $tkey->setOtherData($otherData);
811
812 1
        return $tkey;
813
    }
814
815
    /**
816
     * @param int    $certificateUsage
817
     * @param int    $selector
818
     * @param int    $matchingType
819
     * @param string $certificateAssociationData
820
     *
821
     * @return TLSA
822
     */
823 1
    public static function TLSA(int $certificateUsage, int $selector, int $matchingType, string $certificateAssociationData): TLSA
824
    {
825 1
        $tlsa = new TLSA();
826 1
        $tlsa->setCertificateUsage($certificateUsage);
827 1
        $tlsa->setSelector($selector);
828 1
        $tlsa->setMatchingType($matchingType);
829 1
        $tlsa->setCertificateAssociationData($certificateAssociationData);
830
831 1
        return $tlsa;
832
    }
833
834
    /**
835
     * @param string    $algorithmName
836
     * @param \DateTime $timeSigned
837
     * @param int       $fudge
838
     * @param string    $mac
839
     * @param int       $originalId
840
     * @param int       $error
841
     * @param string    $otherData
842
     *
843
     * @return TSIG
844
     */
845 1
    public static function TSIG(string $algorithmName, \DateTime $timeSigned, int $fudge, string $mac, int $originalId, int $error, string $otherData): TSIG
846
    {
847 1
        $tsig = new TSIG();
848 1
        $tsig->setAlgorithmName($algorithmName);
849 1
        $tsig->setTimeSigned($timeSigned);
850 1
        $tsig->setFudge($fudge);
851 1
        $tsig->setMac($mac);
852 1
        $tsig->setOriginalId($originalId);
853 1
        $tsig->setError($error);
854 1
        $tsig->setOtherData($otherData);
855
856 1
        return $tsig;
857
    }
858
859
    /**
860
     * @param int    $priority
861
     * @param int    $weight
862
     * @param string $target
863
     *
864
     * @return URI
865
     */
866 6
    public static function URI(int $priority, int $weight, string $target): URI
867
    {
868 6
        $uri = new URI();
869 6
        $uri->setPriority($priority);
870 4
        $uri->setWeight($weight);
871 2
        $uri->setTarget($target);
872
873 1
        return $uri;
874
    }
875
}
876