PHP Classes

File: tests/unit/HexTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   PHP Sodium Compat   tests/unit/HexTest.php   Download  
File: tests/unit/HexTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Sodium Compat
Cryptographic functions of libsodium in pure PHP
Author: By
Last change:
Date: 1 year ago
Size: 1,138 bytes
 

Contents

Class file image Download
<?php

class HexTest extends PHPUnit_Framework_TestCase
{
    public function
hexProvider()
    {
        return array(
            array(
'DEADBEEF', '', "\xde\xad\xbe\xef", false),
            array(
'DeAdBeeF', '', "\xde\xad\xbe\xef", false),
            array(
"De\nAdBe\neF", "\n", "\xde\xad\xbe\xef", false),
            array(
"De\nAdBe eF", "\n", "\xde\xad\xbe\xef", true),
            array(
"De\nAdBe eF", "\n ", "\xde\xad\xbe\xef", false),
            array(
"De AdBe eF", " ", "\xde\xad\xbe\xef", false),
        );
    }

   
/**
     * @dataProvider hexProvider
     */
   
public function testHex2Bin($hex, $ignore, $binary, $fail)
    {
        try {
           
$decoded = ParagonIE_Sodium_Compat::hex2bin($hex, $ignore);
           
$this->assertFalse($fail, 'This should have failed but did not!');
           
$this->assertSame($binary, $decoded, 'Binary mismatch');
        } catch (
RangeException $ex) {
           
$this->assertTrue($fail, 'An unexpected hex2bin failure occurred');
        } catch (
SodiumException $ex) {
           
$this->assertTrue($fail, 'An unexpected hex2bin failure occurred');
        }
    }
}