Completed
Branch Message (499c8f)
by Sam
03:03
created

Factory::SIG()   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 4
    public static function newRdataFromName(string $name): RdataInterface
32
    {
33 4
        if (!self::isTypeImplemented($name)) {
34 1
            throw new UnsupportedTypeException($name);
35
        }
36
37 3
        $className = self::getRdataClassName($name);
38
39 3
        return new $className();
40
    }
41
42
    /**
43
     * @param int $id
44
     *
45
     * @return RdataInterface
46
     *
47
     * @throws UnsupportedTypeException
48
     */
49 3
    public static function newRdataFromId(int $id): RdataInterface
50
    {
51 3
        return self::newRdataFromName(Types::getName($id));
52
    }
53
54
    /**
55
     * @param string $name
56
     *
57
     * @return bool
58
     */
59 24
    public static function isTypeImplemented(string $name): bool
60
    {
61 24
        return class_exists(self::getRdataClassName($name));
62
    }
63
64
    /**
65
     * @param int $typeCode
66
     *
67
     * @return bool
68
     */
69 3
    public static function isTypeCodeImplemented(int $typeCode): bool
70
    {
71
        try {
72 3
            return self::isTypeImplemented(Types::getName($typeCode));
73 2
        } catch (UnsupportedTypeException $e) {
74 2
            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 21
    public static function textToRdataType(string $type, string $text): RdataInterface
88
    {
89 21
        if (1 === preg_match('/^TYPE(\d+)$/', $type, $matches)) {
90 3
            $typeCode = (int) $matches[1];
91 3
            if (self::isTypeCodeImplemented($typeCode)) {
92 2
                $type = Types::getName($typeCode);
93
            } else {
94 2
                $rdata = UnknownType::fromText($text);
95 2
                $rdata->setTypeCode($typeCode);
96
97 2
                return $rdata;
98
            }
99
        }
100
101 20
        if (!self::isTypeImplemented($type)) {
102 2
            return new PolymorphicRdata($type, $text);
103
        }
104
105 18
        if (1 === preg_match('/^\\\#\s+(\d+)(\s[a-f0-9\s]+)?$/i', $text, $matches)) {
106 2
            if ('0' === $matches[1]) {
107
                $className = self::getRdataClassName($type);
108
109
                return new $className();
110
            }
111 2
            $wireFormat = hex2bin(str_replace(Tokens::SPACE, '', $matches[2]));
112
113
            /** @var callable $callable */
114 2
            $callable = self::getRdataClassName($type).'::fromWire';
115
116 2
            return call_user_func($callable, $wireFormat);
117
        }
118
119
        /** @var callable $callable */
120 16
        $callable = self::getRdataClassName($type).'::fromText';
121
122 16
        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 32
    public static function getRdataClassName(string $type): string
133
    {
134 32
        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 13
    public static function AAAA(string $address): AAAA
145
    {
146 13
        $rdata = new AAAA();
147 13
        $rdata->setAddress($address);
148
149 13
        return $rdata;
150
    }
151
152
    /**
153
     * Create a new A R-Data object.
154
     *
155
     * @param string $address
156
     *
157
     * @return A
158
     */
159 16
    public static function A(string $address): A
160
    {
161 16
        $rdata = new A();
162 16
        $rdata->setAddress($address);
163
164 16
        return $rdata;
165
    }
166
167
    /**
168
     * Create a new CNAME object.
169
     *
170
     * @param string $cname
171
     *
172
     * @return CNAME
173
     */
174 10
    public static function CNAME(string $cname): CNAME
175
    {
176 10
        $rdata = new CNAME();
177 10
        $rdata->setTarget($cname);
178
179 10
        return $rdata;
180
    }
181
182
    /**
183
     * @param string $cpu
184
     * @param string $os
185
     *
186
     * @return HINFO
187
     */
188 10
    public static function HINFO(string $cpu, string $os): HINFO
189
    {
190 10
        $rdata = new HINFO();
191 10
        $rdata->setCpu($cpu);
192 10
        $rdata->setOs($os);
193
194 10
        return $rdata;
195
    }
196
197
    /**
198
     * @param int    $preference
199
     * @param string $exchange
200
     *
201
     * @return MX
202
     */
203 12
    public static function MX(int $preference, string $exchange): MX
204
    {
205 12
        $rdata = new MX();
206 12
        $rdata->setPreference($preference);
207 12
        $rdata->setExchange($exchange);
208
209 12
        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 15
    public static function SOA(string $mname, string $rname, int $serial, int $refresh, int $retry, int $expire, int $minimum): SOA
224
    {
225 15
        $rdata = new SOA();
226 15
        $rdata->setMname($mname);
227 15
        $rdata->setRname($rname);
228 15
        $rdata->setSerial($serial);
229 15
        $rdata->setRefresh($refresh);
230 15
        $rdata->setRetry($retry);
231 15
        $rdata->setExpire($expire);
232 15
        $rdata->setMinimum($minimum);
233
234 15
        return $rdata;
235
    }
236
237
    /**
238
     * @param string $nsdname
239
     *
240
     * @return NS
241
     */
242 14
    public static function NS(string $nsdname): NS
243
    {
244 14
        $rdata = new NS();
245 14
        $rdata->setTarget($nsdname);
246
247 14
        return $rdata;
248
    }
249
250
    /**
251
     * @param string $text
252
     *
253
     * @return TXT
254
     */
255 11
    public static function TXT(string $text): TXT
256
    {
257 11
        $txt = new TXT();
258 11
        $txt->setText($text);
259
260 11
        return $txt;
261
    }
262
263
    /**
264
     * @param string $text
265
     *
266
     * @return SPF
267
     */
268 2
    public static function SPF(string $text): SPF
269
    {
270 2
        $spf = new SPF();
271 2
        $spf->setText($text);
272
273 2
        return $spf;
274
    }
275
276
    /**
277
     * @param string $target
278
     *
279
     * @return DNAME
280
     */
281 10
    public static function DNAME(string $target): DNAME
282
    {
283 10
        $rdata = new DNAME();
284 10
        $rdata->setTarget($target);
285
286 10
        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 11
    public static function LOC(float $lat, float $lon, $alt = 0.0, $size = 1.0, $hp = 10000.0, $vp = 10.0): LOC
300
    {
301 11
        $loc = new LOC();
302 11
        $loc->setLatitude($lat);
303 11
        $loc->setLongitude($lon);
304 11
        $loc->setAltitude($alt);
305 11
        $loc->setSize($size);
306 11
        $loc->setHorizontalPrecision($hp);
307 11
        $loc->setVerticalPrecision($vp);
308
309 11
        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 2
    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 2
        $rrsig = new RRSIG();
394 2
        $rrsig->setTypeCovered($typeCovered);
395 2
        $rrsig->setAlgorithm($algorithm);
396 2
        $rrsig->setLabels($labels);
397 2
        $rrsig->setOriginalTtl($originalTtl);
398 2
        $rrsig->setSignatureExpiration($signatureExpiration);
399 2
        $rrsig->setSignatureInception($signatureInception);
400 2
        $rrsig->setKeyTag($keyTag);
401 2
        $rrsig->setSignersName($signersName);
402 2
        $rrsig->setSignature($signature);
403
404 2
        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 1
    public static function AFSDB(int $subType, string $hostname): AFSDB
471
    {
472 1
        $afsdb = new AFSDB();
473 1
        $afsdb->setSubType($subType);
474 1
        $afsdb->setHostname($hostname);
475
476 1
        return $afsdb;
477
    }
478
479
    /**
480
     * @param int    $flags
481
     * @param int    $algorithm
482
     * @param string $publicKey
483
     *
484
     * @return CDNSKEY
485
     */
486 1
    public static function CDNSKEY(int $flags, int $algorithm, string $publicKey): CDNSKEY
487
    {
488 1
        $cdnskey = new CDNSKEY();
489 1
        $cdnskey->setFlags($flags);
490 1
        $cdnskey->setAlgorithm($algorithm);
491 1
        $cdnskey->setPublicKey($publicKey);
492
493 1
        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 1
    public static function CDS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): CDS
505
    {
506 1
        $cds = new CDS();
507 1
        $cds->setKeyTag($keyTag);
508 1
        $cds->setAlgorithm($algorithm);
509 1
        $cds->setDigest($digest);
510 1
        $cds->setDigestType($digestType);
511
512 1
        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 4
    public static function DHCID(?string $digest, int $identifierType, ?string $identifier = null, ?string $fqdn = null): DHCID
553
    {
554 4
        $dhcid = new DHCID();
555 4
        if (null !== $digest) {
556 3
            $dhcid->setIdentifierType($identifierType);
557 3
            $dhcid->setDigest($digest);
558
559 3
            return $dhcid;
560
        }
561
562 4
        if (null === $identifier || null === $fqdn) {
563 1
            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 1
    public static function DLV(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DLV
581
    {
582 1
        $rdata = new DLV();
583 1
        $rdata->setKeyTag($keyTag);
584 1
        $rdata->setAlgorithm($algorithm);
585 1
        $rdata->setDigest($digest);
586 1
        $rdata->setDigestType($digestType);
587
588 1
        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 1
    public static function KEY(int $flags, int $protocol, int $algorithm, string $publicKey): KEY
637
    {
638 1
        $key = new KEY();
639 1
        $key->setFlags($flags);
640 1
        $key->setProtocol($protocol);
641 1
        $key->setAlgorithm($algorithm);
642 1
        $key->setPublicKey($publicKey);
643
644 1
        return $key;
645
    }
646
647
    /**
648
     * @param int    $preference
649
     * @param string $exchanger
650
     *
651
     * @return KX
652
     */
653 1
    public static function KX(int $preference, string $exchanger): KX
654
    {
655 1
        $kx = new KX();
656 1
        $kx->setPreference($preference);
657 1
        $kx->setExchanger($exchanger);
658
659 1
        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 2
    public static function NSEC3PARAM(int $hashAlgorithm, int $flags, int $iterations, string $salt): NSEC3PARAM
717
    {
718 2
        $nsec3param = new NSEC3PARAM();
719 2
        $nsec3param->setHashAlgorithm($hashAlgorithm);
720 2
        $nsec3param->setFlags($flags);
721 2
        $nsec3param->setIterations($iterations);
722 2
        $nsec3param->setSalt($salt);
723
724 2
        return $nsec3param;
725
    }
726
727 1
    public static function RP(string $mboxDomain, string $txtDomain): RP
728
    {
729 1
        $rp = new RP();
730 1
        $rp->setMailboxDomainName($mboxDomain);
731 1
        $rp->setTxtDomainName($txtDomain);
732
733 1
        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 1
    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 1
        $sig = new SIG();
754 1
        $sig->setTypeCovered($typeCovered);
755 1
        $sig->setAlgorithm($algorithm);
756 1
        $sig->setLabels($labels);
757 1
        $sig->setOriginalTtl($originalTtl);
758 1
        $sig->setSignatureExpiration($signatureExpiration);
759 1
        $sig->setSignatureInception($signatureInception);
760 1
        $sig->setKeyTag($keyTag);
761 1
        $sig->setSignersName($signersName);
762 1
        $sig->setSignature($signature);
763
764 1
        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 1
    public static function TA(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): TA
793
    {
794 1
        $ta = new TA();
795 1
        $ta->setKeyTag($keyTag);
796 1
        $ta->setAlgorithm($algorithm);
797 1
        $ta->setDigest($digest);
798 1
        $ta->setDigestType($digestType);
799
800 1
        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