DNS icon indicating copy to clipboard operation
DNS copied to clipboard

Added support for empty salt ( aka dash )

Open MartinTerp opened this issue 1 year ago • 3 comments

When using \Badcow\DNS\Parser\Parser::parse, and the zone file contains and empty salt in the NSEC3PARAM, it throws an error:

Could not extract Rdata from resource record " 0 NSEC3PARAM 1 0 0 -"."

This is because the setSalt function in Rdata/NSEC3PARAM.php is as follows:

    public function setSalt(string $salt): void
    {
        if (false === $bin = @hex2bin($salt)) {
            throw new \InvalidArgumentException('Salt must be a hexadecimal string.');
        }
        $this->salt = $bin;
    }

This is a problem, because the salt can be empty ( dash ) but this is not support in this function. Adding a simple check to see if its a dash, and just return, resolves this issue.

I dont know if you guys want it written differently, let me know.

This is also a issue in getSalt and fromWire

MartinTerp avatar Oct 07 '24 19:10 MartinTerp

Im not a wire guy so i hope you will check that function

MartinTerp avatar Oct 07 '24 19:10 MartinTerp

@MartinTerp Thank you for the PR. Could you please write a test case? I'm happy to work on the fromWire method, but a test case helps alot.

samuelwilliams avatar Oct 27 '24 06:10 samuelwilliams

Sure, do you want it in the "public function testFactory(): void" function, or its own?

MartinTerp avatar Nov 04 '24 13:11 MartinTerp