public function hashcashVerify($hashcashStr, $resource, $bits = null) { #$this->log('debug', 'hashcash: '.$hashcashStr); if ($bits === null) { $bits = static::HASHCASH_BITS_MIN; } $hashcash = new Hashcash(); $hashcash->setExpiration(static::HASHCASH_EXPIRATION); try { if ($hashcash->verify($hashcashStr)) { #$this->log('debug', 'bits: '.$hashcash->getBits()); $added = false; if ($hashcash->getVersion() >= 1 && $hashcash->getBits() >= $bits && $hashcash->getResource() == $resource && ($added = $this->getHashcashDb()->addHashcash($hashcash))) { #$this->log('debug', 'hashcash: OK'); return true; } else { $this->log('error', 'hashcash verification failed'); $this->log('error', 'hashcash version: ' . $hashcash->getVersion()); $this->log('error', 'hashcash bit: ' . $hashcash->getBits() . ' (min: ' . $bits . ')'); $this->log('error', 'hashcash resource: ' . $hashcash->getResource() . ' (' . $resource . ')'); $this->log('error', 'hashcash added: ' . ($added ? 'yes' : 'no')); } } } catch (Exception $e) { $this->log('warning', $e->getMessage()); } // @codeCoverageIgnoreEnd $this->log('debug', 'hashcash: ' . $hashcashStr . ' failed'); return false; }
public function testSetGet2() { #$this->assertTrue(true); return; $hashcash = new Hashcash(5, 'test1'); $this->assertEquals(1, $hashcash->getVersion()); $this->assertEquals(5, $hashcash->getBits()); $this->assertEquals(date('ymd'), $hashcash->getDate()); $hashcash = new Hashcash(); $hashcash->setVersion(1); $hashcash->setBits(5); $hashcash->setDate('140422'); $hashcash->setResource('mint1'); $hashcash->setExtension('ext1'); $hashcash->setSalt('salt1'); $hashcash->setSuffix('suffix1'); $this->assertEquals(1, $hashcash->getVersion()); $this->assertEquals(5, $hashcash->getBits()); $this->assertEquals('140422', $hashcash->getDate()); $this->assertEquals('mint1', $hashcash->getResource()); $this->assertEquals('ext1', $hashcash->getExtension()); $this->assertEquals('salt1', $hashcash->getSalt()); $this->assertEquals('suffix1', $hashcash->getSuffix()); }