Hash: add __toString() method

This commit is contained in:
terrafrost 2020-04-18 21:36:42 -05:00
parent 10ce0b9b21
commit 881fbd78ee
4 changed files with 14 additions and 6 deletions

View File

@ -388,7 +388,7 @@ abstract class AsymmetricKey
*/
public function getHash()
{
return $this->hash->getHash();
return clone $this->hash;
}
/**

View File

@ -1462,4 +1462,12 @@ class Hash
return $temp;
}
/**
* __toString() magic method
*/
public function __toString()
{
return $this->getHash();
}
}

View File

@ -669,7 +669,7 @@ abstract class RSA extends AsymmetricKey
*/
public function getMGFHash()
{
return $this->mgfHash->getHash();
return clone $this->mgfHash;
}
/**

View File

@ -170,17 +170,17 @@ HERE;
->withSaltLength(5)
->withMGFHash('sha512');
$this->assertSame('sha1', $rsa->getHash());
$this->assertEquals('sha1', $rsa->getHash());
$this->assertSame(5, $rsa->getSaltLength());
$this->assertSame('sha512', $rsa->getMGFHash());
$this->assertEquals('sha512', $rsa->getMGFHash());
$rsa = $rsa
->withHash('sha512')
->withSaltLength(6)
->withMGFHash('sha1');
$this->assertSame('sha512', $rsa->getHash());
$this->assertEquals('sha512', $rsa->getHash());
$this->assertSame(6, $rsa->getSaltLength());
$this->assertSame('sha1', $rsa->getMGFHash());
$this->assertEquals('sha1', $rsa->getMGFHash());
}
}