import assert from "assert" ; import { dnsLowerCase } from "../../util/dns-equal" ; import { DNSLabelCoder } from "../DNSLabelCoder" ; import { DecodedData , RType } from "../DNSPacket" ; import { RecordRepresentation , ResourceRecord } from "../ResourceRecord" ; export class CNAMERecord extends ResourceRecord { public static readonly DEFAULT_TTL = ResourceRecord . RR_DEFAULT_TTL ; readonly cname : string ; private lowerCasedCName ? : string ; constructor ( name , cname , flushFlag ? , ttl ? ) ; constructor ( header , cname ) ; constructor ( name , cname , flushFlag ? , ttl ? ) { if ( typeof name === "string" ) { super ( name , RType . CNAME , ttl , flushFlag ) ; } else { assert ( name . type === RType . CNAME ) ; super ( name ) ; } if ( ! cname . endsWith ( "." ) ) { cname += "." ; } this . cname = cname ; } public getLowerCasedCName ( ) { return this . lowerCasedCName || ( this . lowerCasedCName = dnsLowerCase ( this . cname ) ) ; } protected getRDataEncodingLength ( coder ) { return coder . getNameLength ( this . cname ) ; } protected encodeRData ( coder , buffer , offset ) { const oldOffset = offset ; const cnameLength = coder . encodeName ( this . cname , offset ) ; offset += cnameLength ; return offset - oldOffset ; } public static decodeData ( coder , header , buffer , offset ) { const oldOffset = offset ; const decodedName = coder . decodeName ( offset ) ; offset += decodedName . readBytes ; return { data : new CNAMERecord ( header , decodedName . data ) , readBytes : offset - oldOffset , } ; } public clone ( ) { return new CNAMERecord ( this . getRecordRepresentation ( ) , this . cname ) ; } public dataAsString ( ) { return this . cname ; } public dataEquals ( record ) { return this . getLowerCasedCName ( ) === record . getLowerCasedCName ( ) ; } }