示例#1
0
 public function testHexBinConversionsWorkCorrectly()
 {
     $hex = "5a4b";
     $bin = "ZK";
     $this->assertEquals($hex, HashUtils::binToHex($bin));
     $this->assertEquals($bin, HashUtils::hexToBin($hex));
 }
示例#2
0
 /**
  * Add a checksum to the tree hash directly
  *
  * @param string $checksum     The checksum to add
  * @param bool   $inBinaryForm Whether or not the checksum is already in binary form
  *
  * @return self
  * @throws LogicException if the root tree hash is already calculated
  */
 public function addChecksum($checksum, $inBinaryForm = false)
 {
     // Error if hash is already calculated
     if ($this->hash) {
         throw new LogicException('You may not add more checksums to a finalized tree hash.');
     }
     // Convert the checksum to binary form if necessary
     $this->checksums[] = $inBinaryForm ? $checksum : HashUtils::hexToBin($checksum);
     return $this;
 }