Passed
Branch master (8940db)
by Sam
02:38
created

Factory::RRSIG()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 2
b 0
f 0
nc 1
nop 9
dl 0
loc 16
ccs 12
cts 12
cp 1
crap 1
rs 9.9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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(Types::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(Types::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 = Types::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
        $txt = new TXT();
258 10
        $txt->setText($text);
259
260 10
        return $txt;
261
    }
262
263
    /**
264
     * @param string $text
265
     *
266
     * @return SPF
267
     */
268 1
    public static function SPF(string $text): SPF
269
    {
270 1
        $spf = new SPF();
271 1
        $spf->setText($text);
272
273 1
        return $spf;
274
    }
275
276
    /**
277
     * @param string $target
278
     *
279
     * @return DNAME
280
     */
281 9
    public static function DNAME(string $target): DNAME
282
    {
283 9
        $rdata = new DNAME();
284 9
        $rdata->setTarget($target);
285
286 9
        return $rdata;
287
    }
288
289
    /**
290
     * @param float $lat
291
     * @param float $lon
292
     * @param float $alt
293
     * @param float $size
294
     * @param float $hp
295
     * @param float $vp
296
     *
297
     * @return LOC
298
     */
299 10
    public static function LOC(float $lat, float $lon, $alt = 0.0, $size = 1.0, $hp = 10000.0, $vp = 10.0): LOC
300
    {
301 10
        $loc = new LOC();
302 10
        $loc->setLatitude($lat);
303 10
        $loc->setLongitude($lon);
304 10
        $loc->setAltitude($alt);
305 10
        $loc->setSize($size);
306 10
        $loc->setHorizontalPrecision($hp);
307 10
        $loc->setVerticalPrecision($vp);
308
309 10
        return $loc;
310
    }
311
312
    /**
313
     * @param string $target
314
     *
315
     * @return PTR
316
     */
317 2
    public static function PTR(string $target): PTR
318
    {
319 2
        $ptr = new PTR();
320 2
        $ptr->setTarget($target);
321
322 2
        return $ptr;
323
    }
324
325
    /**
326
     * @param int    $flags
327
     * @param int    $algorithm
328
     * @param string $publicKey
329
     *
330
     * @return DNSKEY
331
     */
332 1
    public static function DNSKEY(int $flags, int $algorithm, string $publicKey): DNSKEY
333
    {
334 1
        $rdata = new DNSKEY();
335 1
        $rdata->setFlags($flags);
336 1
        $rdata->setAlgorithm($algorithm);
337 1
        $rdata->setPublicKey($publicKey);
338
339 1
        return $rdata;
340
    }
341
342
    /**
343
     * @param int    $keyTag
344
     * @param int    $algorithm
345
     * @param string $digest
346
     * @param int    $digestType
347
     *
348
     * @return DS
349
     */
350 1
    public static function DS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DS
351
    {
352 1
        $rdata = new DS();
353 1
        $rdata->setKeyTag($keyTag);
354 1
        $rdata->setAlgorithm($algorithm);
355 1
        $rdata->setDigest($digest);
356 1
        $rdata->setDigestType($digestType);
357
358 1
        return $rdata;
359
    }
360
361
    /**
362
     * @param string $nextDomainName
363
     * @param array  $types
364
     *
365
     * @return NSEC
366
     */
367 1
    public static function NSEC(string $nextDomainName, array $types): NSEC
368
    {
369 1
        $rdata = new NSEC();
370 1
        $rdata->setNextDomainName($nextDomainName);
371 1
        array_map([$rdata, 'addType'], $types);
372
373 1
        return $rdata;
374
    }
375
376
    /**
377
     * @param string    $typeCovered
378
     * @param int       $algorithm
379
     * @param int       $labels
380
     * @param int       $originalTtl
381
     * @param \DateTime $signatureExpiration
382
     * @param \DateTime $signatureInception
383
     * @param int       $keyTag
384
     * @param string    $signersName
385
     * @param string    $signature
386
     *
387
     * @return RRSIG
388
     */
389 1
    public static function RRSIG(string $typeCovered, int $algorithm, int $labels, int $originalTtl,
390
                                    \DateTime $signatureExpiration, \DateTime $signatureInception, int $keyTag,
391
                                    string $signersName, string $signature): RRSIG
392
    {
393 1
        $rrsig = new RRSIG();
394 1
        $rrsig->setTypeCovered($typeCovered);
395 1
        $rrsig->setAlgorithm($algorithm);
396 1
        $rrsig->setLabels($labels);
397 1
        $rrsig->setOriginalTtl($originalTtl);
398 1
        $rrsig->setSignatureExpiration($signatureExpiration);
399 1
        $rrsig->setSignatureInception($signatureInception);
400 1
        $rrsig->setKeyTag($keyTag);
401 1
        $rrsig->setSignersName($signersName);
402 1
        $rrsig->setSignature($signature);
403
404 1
        return $rrsig;
405
    }
406
407
    /**
408
     * @param int    $priority
409
     * @param int    $weight
410
     * @param int    $port
411
     * @param string $target
412
     *
413
     * @return SRV
414
     */
415 1
    public static function SRV(int $priority, int $weight, int $port, string $target): SRV
416
    {
417 1
        $rdata = new SRV();
418 1
        $rdata->setPriority($priority);
419 1
        $rdata->setWeight($weight);
420 1
        $rdata->setPort($port);
421 1
        $rdata->setTarget($target);
422
423 1
        return $rdata;
424
    }
425
426
    /**
427
     * @param IPBlock[] $includedRanges
428
     * @param IPBlock[] $excludedRanges
429
     *
430
     * @return APL
431
     */
432 2
    public static function APL(array $includedRanges = [], array $excludedRanges = []): APL
433
    {
434 2
        $rdata = new APL();
435
436 2
        foreach ($includedRanges as $ipBlock) {
437 2
            $rdata->addAddressRange($ipBlock, true);
438
        }
439
440 2
        foreach ($excludedRanges as $ipBlock) {
441 2
            $rdata->addAddressRange($ipBlock, false);
442
        }
443
444 2
        return $rdata;
445
    }
446
447
    /**
448
     * @param int    $flag
449
     * @param string $tag
450
     * @param string $value
451
     *
452
     * @return CAA
453
     */
454 1
    public static function CAA(int $flag, string $tag, string $value): CAA
455
    {
456 1
        $rdata = new CAA();
457 1
        $rdata->setFlag($flag);
458 1
        $rdata->setTag($tag);
459 1
        $rdata->setValue($value);
460
461 1
        return $rdata;
462
    }
463
464
    /**
465
     * @param int    $subType
466
     * @param string $hostname
467
     *
468
     * @return AFSDB
469
     */
470
    public static function AFSDB(int $subType, string $hostname): AFSDB
471
    {
472
        $afsdb = new AFSDB();
473
        $afsdb->setSubType($subType);
474
        $afsdb->setHostname($hostname);
475
476
        return $afsdb;
477
    }
478
479
    /**
480
     * @param int    $flags
481
     * @param int    $algorithm
482
     * @param string $publicKey
483
     *
484
     * @return CDNSKEY
485
     */
486
    public static function CDNSKEY(int $flags, int $algorithm, string $publicKey): CDNSKEY
487
    {
488
        $cdnskey = new CDNSKEY();
489
        $cdnskey->setFlags($flags);
490
        $cdnskey->setAlgorithm($algorithm);
491
        $cdnskey->setPublicKey($publicKey);
492
493
        return $cdnskey;
494
    }
495
496
    /**
497
     * @param int    $keyTag
498
     * @param int    $algorithm
499
     * @param string $digest
500
     * @param int    $digestType
501
     *
502
     * @return CDS
503
     */
504
    public static function CDS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): CDS
505
    {
506
        $cds = new CDS();
507
        $cds->setKeyTag($keyTag);
508
        $cds->setAlgorithm($algorithm);
509
        $cds->setDigest($digest);
510
        $cds->setDigestType($digestType);
511
512
        return $cds;
513
    }
514
515
    /**
516
     * @param int|string $certificateType
517
     * @param int        $keyTag
518
     * @param int        $algorithm
519
     * @param string     $certificate
520
     *
521
     * @return CERT
522
     */
523 1
    public static function CERT($certificateType, int $keyTag, int $algorithm, string $certificate): CERT
524
    {
525 1
        $cert = new CERT();
526 1
        $cert->setCertificateType($certificateType);
527 1
        $cert->setKeyTag($keyTag);
528 1
        $cert->setAlgorithm($algorithm);
529 1
        $cert->setCertificate($certificate);
530
531 1
        return $cert;
532
    }
533
534 1
    public static function CSYNC(int $soaSerial, int $flags, array $types): CSYNC
535
    {
536 1
        $csync = new CSYNC();
537 1
        $csync->setSoaSerial($soaSerial);
538 1
        $csync->setFlags($flags);
539 1
        array_map([$csync, 'addType'], $types);
540
541 1
        return $csync;
542
    }
543
544
    /**
545
     * @param string|null $digest         Set to &null if the $identifier and $fqdn are known
546
     * @param int         $identifierType 16-bit integer
547
     * @param string|null $identifier     This is ignored if $digest is not &null
548
     * @param string|null $fqdn           This is ignored if $digest is not &null
549
     *
550
     * @return DHCID
551
     */
552 3
    public static function DHCID(?string $digest, int $identifierType, ?string $identifier = null, ?string $fqdn = null): DHCID
553
    {
554 3
        $dhcid = new DHCID();
555 3
        if (null !== $digest) {
556
            $dhcid->setIdentifierType($identifierType);
557
            $dhcid->setDigest($digest);
558
559
            return $dhcid;
560
        }
561
562 3
        if (null === $identifier || null === $fqdn) {
563
            throw new \InvalidArgumentException('Identifier and FQDN cannot be null if digest is null.');
564
        }
565
566 3
        $dhcid->setIdentifier($identifierType, $identifier);
567 3
        $dhcid->setFqdn($fqdn);
568
569 3
        return $dhcid;
570
    }
571
572
    /**
573
     * @param int    $keyTag
574
     * @param int    $algorithm
575
     * @param string $digest
576
     * @param int    $digestType
577
     *
578
     * @return DLV
579
     */
580
    public static function DLV(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DLV
581
    {
582
        $rdata = new DLV();
583
        $rdata->setKeyTag($keyTag);
584
        $rdata->setAlgorithm($algorithm);
585
        $rdata->setDigest($digest);
586
        $rdata->setDigestType($digestType);
587
588
        return $rdata;
589
    }
590
591
    /**
592
     * @param int      $publicKeyAlgorithm
593
     * @param string   $hostIdentityTag
594
     * @param string   $publicKey
595
     * @param string[] $rendezvousServers
596
     *
597
     * @return HIP
598
     */
599 1
    public static function HIP(int $publicKeyAlgorithm, string $hostIdentityTag, string $publicKey, array $rendezvousServers): HIP
600
    {
601 1
        $hip = new HIP();
602 1
        $hip->setPublicKeyAlgorithm($publicKeyAlgorithm);
603 1
        $hip->setHostIdentityTag($hostIdentityTag);
604 1
        $hip->setPublicKey($publicKey);
605 1
        array_map([$hip, 'addRendezvousServer'], $rendezvousServers);
606
607 1
        return $hip;
608
    }
609
610
    /**
611
     * @param int         $precedence an 8-bit unsigned integer
612
     * @param string|null $gateway    either &null for no gateway, a fully qualified domain name, or an IPv4 or IPv6 address
613
     * @param int         $algorithm  either IPSECKEY::ALGORITHM_NONE, IPSECKEY::ALGORITHM_DSA, IPSECKEY::ALGORITHM_RSA, or IPSECKEY::ALGORITHM_ECDSA
614
     * @param string|null $publicKey  base64 encoded public key
615
     *
616
     * @return IPSECKEY
617
     */
618 6
    public static function IPSECKEY(int $precedence, ?string $gateway, int $algorithm = 0, ?string $publicKey = null): IPSECKEY
619
    {
620 6
        $ipseckey = new IPSECKEY();
621 6
        $ipseckey->setPrecedence($precedence);
622 6
        $ipseckey->setGateway($gateway);
623 6
        $ipseckey->setPublicKey($algorithm, $publicKey);
624
625 6
        return $ipseckey;
626
    }
627
628
    /**
629
     * @param int    $flags
630
     * @param int    $protocol
631
     * @param int    $algorithm
632
     * @param string $publicKey
633
     *
634
     * @return KEY
635
     */
636
    public static function KEY(int $flags, int $protocol, int $algorithm, string $publicKey): KEY
637
    {
638
        $key = new KEY();
639
        $key->setFlags($flags);
640
        $key->setProtocol($protocol);
641
        $key->setAlgorithm($algorithm);
642
        $key->setPublicKey($publicKey);
643
644
        return $key;
645
    }
646
647
    /**
648
     * @param int    $preference
649
     * @param string $exchanger
650
     *
651
     * @return KX
652
     */
653
    public static function KX(int $preference, string $exchanger): KX
654
    {
655
        $kx = new KX();
656
        $kx->setPreference($preference);
657
        $kx->setExchanger($exchanger);
658
659
        return $kx;
660
    }
661
662
    /**
663
     * @param int    $order
664
     * @param int    $preference
665
     * @param string $flags
666
     * @param string $services
667
     * @param string $regexp
668
     * @param string $replacement
669
     *
670
     * @return NAPTR
671
     */
672 2
    public static function NAPTR(int $order, int $preference, string $flags, string $services, string $regexp, string $replacement): NAPTR
673
    {
674 2
        $naptr = new NAPTR();
675 2
        $naptr->setOrder($order);
676 2
        $naptr->setPreference($preference);
677 2
        $naptr->setFlags($flags);
678 2
        $naptr->setServices($services);
679 2
        $naptr->setRegexp($regexp);
680 2
        $naptr->setReplacement($replacement);
681
682 2
        return $naptr;
683
    }
684
685
    /**
686
     * @param int    $hashAlgorithm
687
     * @param bool   $unsignedDelegationsCovered
688
     * @param int    $iterations
689
     * @param string $salt
690
     * @param string $nextHashedOwnerName
691
     * @param array  $types
692
     *
693
     * @return NSEC3
694
     */
695 1
    public static function NSEC3(int $hashAlgorithm, bool $unsignedDelegationsCovered, int $iterations, string $salt, string $nextHashedOwnerName, array $types): NSEC3
696
    {
697 1
        $nsec3 = new NSEC3();
698 1
        $nsec3->setHashAlgorithm($hashAlgorithm);
699 1
        $nsec3->setUnsignedDelegationsCovered($unsignedDelegationsCovered);
700 1
        $nsec3->setIterations($iterations);
701 1
        $nsec3->setSalt($salt);
702 1
        $nsec3->setNextHashedOwnerName($nextHashedOwnerName);
703 1
        array_map([$nsec3, 'addType'], $types);
704
705 1
        return $nsec3;
706
    }
707
708
    /**
709
     * @param int    $hashAlgorithm
710
     * @param int    $flags
711
     * @param int    $iterations
712
     * @param string $salt
713
     *
714
     * @return NSEC3PARAM
715
     */
716 1
    public static function NSEC3PARAM(int $hashAlgorithm, int $flags, int $iterations, string $salt): NSEC3PARAM
717
    {
718 1
        $nsec3param = new NSEC3PARAM();
719 1
        $nsec3param->setHashAlgorithm($hashAlgorithm);
720 1
        $nsec3param->setFlags($flags);
721 1
        $nsec3param->setIterations($iterations);
722 1
        $nsec3param->setSalt($salt);
723
724 1
        return $nsec3param;
725
    }
726
727
    public static function RP(string $mboxDomain, string $txtDomain): RP
728
    {
729
        $rp = new RP();
730
        $rp->setMailboxDomainName($mboxDomain);
731
        $rp->setTxtDomainName($txtDomain);
732
733
        return $rp;
734
    }
735
736
    /**
737
     * @param string    $typeCovered
738
     * @param int       $algorithm
739
     * @param int       $labels
740
     * @param int       $originalTtl
741
     * @param \DateTime $signatureExpiration
742
     * @param \DateTime $signatureInception
743
     * @param int       $keyTag
744
     * @param string    $signersName
745
     * @param string    $signature
746
     *
747
     * @return SIG
748
     */
749
    public static function SIG(string $typeCovered, int $algorithm, int $labels, int $originalTtl,
750
                                 \DateTime $signatureExpiration, \DateTime $signatureInception, int $keyTag,
751
                                 string $signersName, string $signature): SIG
752
    {
753
        $sig = new SIG();
754
        $sig->setTypeCovered($typeCovered);
755
        $sig->setAlgorithm($algorithm);
756
        $sig->setLabels($labels);
757
        $sig->setOriginalTtl($originalTtl);
758
        $sig->setSignatureExpiration($signatureExpiration);
759
        $sig->setSignatureInception($signatureInception);
760
        $sig->setKeyTag($keyTag);
761
        $sig->setSignersName($signersName);
762
        $sig->setSignature($signature);
763
764
        return $sig;
765
    }
766
767
    /**
768
     * @param int    $algorithm
769
     * @param int    $fpType
770
     * @param string $fingerprint
771
     *
772
     * @return SSHFP
773
     */
774 8
    public static function SSHFP(int $algorithm, int $fpType, string $fingerprint): SSHFP
775
    {
776 8
        $sshfp = new SSHFP();
777 8
        $sshfp->setAlgorithm($algorithm);
778 6
        $sshfp->setFingerprintType($fpType);
779 4
        $sshfp->setFingerprint($fingerprint);
780
781 3
        return $sshfp;
782
    }
783
784
    /**
785
     * @param int    $keyTag
786
     * @param int    $algorithm
787
     * @param string $digest
788
     * @param int    $digestType
789
     *
790
     * @return TA
791
     */
792
    public static function TA(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): TA
793
    {
794
        $ta = new TA();
795
        $ta->setKeyTag($keyTag);
796
        $ta->setAlgorithm($algorithm);
797
        $ta->setDigest($digest);
798
        $ta->setDigestType($digestType);
799
800
        return $ta;
801
    }
802
803
    /**
804
     * @param string    $algorithm
805
     * @param \DateTime $inception
806
     * @param \DateTime $expiration
807
     * @param int       $mode
808
     * @param int       $error
809
     * @param string    $keyData    binary string
810
     * @param string    $otherData  binary string
811
     *
812
     * @return TKEY
813
     */
814 1
    public static function TKEY(string $algorithm, \DateTime $inception, \DateTime $expiration, int $mode, int $error, string $keyData, string $otherData = ''): TKEY
815
    {
816 1
        $tkey = new TKEY();
817 1
        $tkey->setAlgorithm($algorithm);
818 1
        $tkey->setInception($inception);
819 1
        $tkey->setExpiration($expiration);
820 1
        $tkey->setMode($mode);
821 1
        $tkey->setError($error);
822 1
        $tkey->setKeyData($keyData);
823 1
        $tkey->setOtherData($otherData);
824
825 1
        return $tkey;
826
    }
827
828
    /**
829
     * @param int    $certificateUsage
830
     * @param int    $selector
831
     * @param int    $matchingType
832
     * @param string $certificateAssociationData
833
     *
834
     * @return TLSA
835
     */
836 1
    public static function TLSA(int $certificateUsage, int $selector, int $matchingType, string $certificateAssociationData): TLSA
837
    {
838 1
        $tlsa = new TLSA();
839 1
        $tlsa->setCertificateUsage($certificateUsage);
840 1
        $tlsa->setSelector($selector);
841 1
        $tlsa->setMatchingType($matchingType);
842 1
        $tlsa->setCertificateAssociationData($certificateAssociationData);
843
844 1
        return $tlsa;
845
    }
846
847
    /**
848
     * @param string    $algorithmName
849
     * @param \DateTime $timeSigned
850
     * @param int       $fudge
851
     * @param string    $mac
852
     * @param int       $originalId
853
     * @param int       $error
854
     * @param string    $otherData
855
     *
856
     * @return TSIG
857
     */
858 1
    public static function TSIG(string $algorithmName, \DateTime $timeSigned, int $fudge, string $mac, int $originalId, int $error, string $otherData): TSIG
859
    {
860 1
        $tsig = new TSIG();
861 1
        $tsig->setAlgorithmName($algorithmName);
862 1
        $tsig->setTimeSigned($timeSigned);
863 1
        $tsig->setFudge($fudge);
864 1
        $tsig->setMac($mac);
865 1
        $tsig->setOriginalId($originalId);
866 1
        $tsig->setError($error);
867 1
        $tsig->setOtherData($otherData);
868
869 1
        return $tsig;
870
    }
871
872
    /**
873
     * @param int    $priority
874
     * @param int    $weight
875
     * @param string $target
876
     *
877
     * @return URI
878
     */
879 6
    public static function URI(int $priority, int $weight, string $target): URI
880
    {
881 6
        $uri = new URI();
882 6
        $uri->setPriority($priority);
883 4
        $uri->setWeight($weight);
884 2
        $uri->setTarget($target);
885
886 1
        return $uri;
887
    }
888
}
889