Skip to content

Commit

Permalink
Add AFSDB and X25 types
Browse files Browse the repository at this point in the history
  • Loading branch information
ben221199 committed Feb 19, 2025
1 parent 67406d2 commit 188384b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/Types/AFSDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace YOCLIB\DNS\Types;

use YOCLIB\DNS\Exceptions\DNSTypeException;
use YOCLIB\DNS\Fields\Field;
use YOCLIB\DNS\Fields\FQDN;
use YOCLIB\DNS\Fields\UnsignedInteger16;

class AFSDB extends Type{

/**
* @param array|Field[] $fields
* @throws DNSTypeException
*/
public function __construct(array $fields){
parent::__construct($fields);
if(count($fields)!==2){
throw new DNSTypeException('Only two fields allowed.');
}
if(!($fields[0] instanceof UnsignedInteger16)){
throw new DNSTypeException('First field should be an UInt16.');
}
if(!($fields[1] instanceof FQDN)){
throw new DNSTypeException('Second field should be a FQDN.');
}
}

}
24 changes: 24 additions & 0 deletions src/Types/X25.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace YOCLIB\DNS\Types;

use YOCLIB\DNS\Exceptions\DNSTypeException;
use YOCLIB\DNS\Fields\CharacterString;
use YOCLIB\DNS\Fields\Field;

class X25 extends Type{

/**
* @param array|Field[] $fields
* @throws DNSTypeException
*/
public function __construct(array $fields){
parent::__construct($fields);
if(count($fields)!==1){
throw new DNSTypeException('Only one field allowed.');
}
if(!($fields[0] instanceof CharacterString)){
throw new DNSTypeException('Field should be a character string.');
}
}

}
20 changes: 18 additions & 2 deletions tests/TypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
use YOCLIB\DNS\Fields\UnsignedInteger8;
use YOCLIB\DNS\Types\A;
use YOCLIB\DNS\Types\AAAA;
use YOCLIB\DNS\Types\AFSDB;
use YOCLIB\DNS\Types\HINFO;
use YOCLIB\DNS\Types\MD;
use YOCLIB\DNS\Types\MINFO;
use YOCLIB\DNS\Types\MX;
use YOCLIB\DNS\Types\NS;
use YOCLIB\DNS\Types\RP;
use YOCLIB\DNS\Types\SOA;
use YOCLIB\DNS\Types\TXT;
use YOCLIB\DNS\Types\WKS;
use YOCLIB\DNS\Types\X25;

class TypesTest extends TestCase{

Expand Down Expand Up @@ -84,7 +87,7 @@ public function testTypes(){
self::assertEquals("\x1Fmy.dotted.response.mail.address\x07example\x03com\x00"."\x1Cmy.dotted.error.mail.address\x07example\x03com\x00",$minfoRecord->serializeToWireFormat());

$mxRecord = new MX([
new UnsignedInteger16('10'),
new UnsignedInteger16(10),
new FQDN('mx','example','com',''),
]);
self::assertEquals('10 mx.example.com.',$mxRecord->serializeToPresentationFormat());
Expand All @@ -100,13 +103,26 @@ public function testTypes(){
self::assertEquals('TEXT \"TEXT\" "TEXT WITH SPACE" "TEXT WITH \"QUOTE\" AND SPACE" "TEXT WITH BACKSPACE (\\\\) AND SPACE"',$txtRecord->serializeToPresentationFormat());
self::assertEquals("\x04TEXT"."\x06\"TEXT\""."\x0FTEXT WITH SPACE"."\x1BTEXT WITH \"QUOTE\" AND SPACE"."\x21TEXT WITH BACKSPACE (\\) AND SPACE",$txtRecord->serializeToWireFormat());

$rpRecord = new MINFO([
$rpRecord = new RP([
new FQDN('mailbox.domainname','example','com',''),
new FQDN('text.domainname','example','com',''),
]);
self::assertEquals('mailbox\.domainname.example.com. text\.domainname.example.com.',$rpRecord->serializeToPresentationFormat());
self::assertEquals("\x12mailbox.domainname\x07example\x03com\x00"."\x0Ftext.domainname\x07example\x03com\x00",$rpRecord->serializeToWireFormat());

$afsdbRecord = new AFSDB([
new UnsignedInteger16(1),
new FQDN('afs','example','com',''),
]);
self::assertEquals('1 afs.example.com.',$afsdbRecord->serializeToPresentationFormat());
self::assertEquals("\x00\x01"."\x03afs\x07example\x03com\x00",$afsdbRecord->serializeToWireFormat());

$x25Record = new X25([
new CharacterString('311061700956'),
]);
self::assertEquals('311061700956',$x25Record->serializeToPresentationFormat());
self::assertEquals("\x0C311061700956",$x25Record->serializeToWireFormat());

$aaaaRecord = new AAAA([
new IPv6Address('::'),
]);
Expand Down

0 comments on commit 188384b

Please sign in to comment.