Pop\Crypt\Sha::setBits PHP Method

setBits() public method

Method to set the cost
public setBits ( integer $bits = 512 ) : self
$bits integer
return self
    public function setBits($bits = 512)
    {
        $bits = (int) $bits;
        if ($bits != 256 && $bits != 512) {
            throw new Exception('Error: The bit setting must be 256 or 512');
        }
        if ($bits == 256 && CRYPT_SHA256 == 0) {
            throw new Exception('Error: SHA 256 hashing is not supported on this system.');
        }
        if ($bits == 512 && CRYPT_SHA512 == 0) {
            throw new Exception('Error: SHA 512 hashing is not supported on this system.');
        }
        $this->bits = $bits;
        return $this;
    }

Usage Example

Example #1
0
 public function testShaBitsException()
 {
     $this->setExpectedException('Pop\\Crypt\\Exception');
     $crypt = new Crypt\Sha();
     $crypt->setBits(100);
 }