Пример #1
0
 /**
  * Convert a binary string into a hexadecimal string without cache-timing
  * leaks
  *
  * @param string $bin_string (raw binary)
  * @return string
  */
 public static function hexEncode(string $bin_string) : string
 {
     return Hex::encode($bin_string);
 }
Пример #2
-1
 public function testEncoding()
 {
     $random_bytes = \random_bytes(31);
     // Backwards compatibility:
     $encoder = Halite::chooseEncoder(false);
     $this->assertSame(Hex::encode($random_bytes), $encoder($random_bytes));
     $encoder = Halite::chooseEncoder(true);
     $this->assertSame(null, $encoder);
     // New encoding in version 3:
     $encoder = Halite::chooseEncoder(Halite::ENCODE_HEX);
     $this->assertSame(Hex::encode($random_bytes), $encoder($random_bytes));
     $encoder = Halite::chooseEncoder(Halite::ENCODE_BASE32);
     $this->assertSame(Base32::encode($random_bytes), $encoder($random_bytes));
     $encoder = Halite::chooseEncoder(Halite::ENCODE_BASE32HEX);
     $this->assertSame(Base32Hex::encode($random_bytes), $encoder($random_bytes));
     $encoder = Halite::chooseEncoder(Halite::ENCODE_BASE64);
     $this->assertSame(Base64::encode($random_bytes), $encoder($random_bytes));
     $encoder = Halite::chooseEncoder(Halite::ENCODE_BASE64URLSAFE);
     $this->assertSame(Base64UrlSafe::encode($random_bytes), $encoder($random_bytes));
 }