Annotation of embedaddon/php/ext/mcrypt/tests/mcrypt_cbc_variation4.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test mcrypt_cbc() function : usage variation 
        !             3: --SKIPIF--
        !             4: <?php 
        !             5: if (!extension_loaded("mcrypt")) {
        !             6:        print "skip - mcrypt extension not loaded"; 
        !             7: }       
        !             8: ?>
        !             9: --FILE--
        !            10: <?php
        !            11: /* Prototype  : string mcrypt_cbc(string cipher, string key, string data, int mode, string iv)
        !            12:  * Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv 
        !            13:  * Source code: ext/mcrypt/mcrypt.c
        !            14:  * Alias to functions: 
        !            15:  */
        !            16: 
        !            17: echo "*** Testing mcrypt_cbc() : usage variation ***\n";
        !            18: 
        !            19: // Define error handler
        !            20: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
        !            21:        if (error_reporting() != 0) {
        !            22:                // report non-silenced errors
        !            23:                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        !            24:        }
        !            25: }
        !            26: set_error_handler('test_error_handler');
        !            27: 
        !            28: // Initialise function arguments not being substituted (if any)
        !            29: $cipher = MCRYPT_TRIPLEDES;
        !            30: $key = b'string_val';
        !            31: $data = b'string_val';
        !            32: $iv = b'01234567';
        !            33: 
        !            34: //get an unset variable
        !            35: $unset_var = 10;
        !            36: unset ($unset_var);
        !            37: 
        !            38: // define some classes
        !            39: class classWithToString
        !            40: {
        !            41:        public function __toString() {
        !            42:                return "Class A object";
        !            43:        }
        !            44: }
        !            45: 
        !            46: class classWithoutToString
        !            47: {
        !            48: }
        !            49: 
        !            50: // heredoc string
        !            51: $heredoc = <<<EOT
        !            52: hello world
        !            53: EOT;
        !            54: 
        !            55: // get a resource variable
        !            56: $fp = fopen(__FILE__, "r");
        !            57: 
        !            58: // add arrays
        !            59: $index_array = array (1, 2, 3);
        !            60: $assoc_array = array ('one' => 1, 'two' => 2);
        !            61: 
        !            62: //array of values to iterate over
        !            63: $inputs = array(
        !            64: 
        !            65:       // float data
        !            66:       'float 10.5' => 10.5,
        !            67:       'float -10.5' => -10.5,
        !            68:       'float 12.3456789000e10' => 12.3456789000e10,
        !            69:       'float -12.3456789000e10' => -12.3456789000e10,
        !            70:       'float .5' => .5,
        !            71: 
        !            72:       // array data
        !            73:       'empty array' => array(),
        !            74:       'int indexed array' => $index_array,
        !            75:       'associative array' => $assoc_array,
        !            76:       'nested arrays' => array('foo', $index_array, $assoc_array),
        !            77: 
        !            78:       // null data
        !            79:       'uppercase NULL' => NULL,
        !            80:       'lowercase null' => null,
        !            81: 
        !            82:       // boolean data
        !            83:       'lowercase true' => true,
        !            84:       'lowercase false' =>false,
        !            85:       'uppercase TRUE' =>TRUE,
        !            86:       'uppercase FALSE' =>FALSE,
        !            87: 
        !            88:       // empty data
        !            89:       'empty string DQ' => "",
        !            90:       'empty string SQ' => '',
        !            91: 
        !            92:       // string data
        !            93:       'string DQ' => "string",
        !            94:       'string SQ' => 'string',
        !            95:       'mixed case string' => "sTrInG",
        !            96:       'heredoc' => $heredoc,
        !            97: 
        !            98:       // object data
        !            99:       'instance of classWithToString' => new classWithToString(),
        !           100:       'instance of classWithoutToString' => new classWithoutToString(),
        !           101: 
        !           102:       // undefined data
        !           103:       'undefined var' => @$undefined_var,
        !           104: 
        !           105:       // unset data
        !           106:       'unset var' => @$unset_var,
        !           107:       
        !           108:       // resource variable
        !           109:       'resource' => $fp      
        !           110: );
        !           111: 
        !           112: // loop through each element of the array for mode
        !           113: 
        !           114: foreach($inputs as $valueType =>$value) {
        !           115:       echo "\n--$valueType--\n";
        !           116:       var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $value, $iv)));
        !           117: };
        !           118: 
        !           119: fclose($fp);
        !           120: 
        !           121: ?>
        !           122: ===DONE===
        !           123: --EXPECTF--
        !           124: *** Testing mcrypt_cbc() : usage variation ***
        !           125: 
        !           126: --float 10.5--
        !           127: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           128: 
        !           129: --float -10.5--
        !           130: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           131: 
        !           132: --float 12.3456789000e10--
        !           133: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           134: 
        !           135: --float -12.3456789000e10--
        !           136: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           137: 
        !           138: --float .5--
        !           139: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           140: 
        !           141: --empty array--
        !           142: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           143: 
        !           144: --int indexed array--
        !           145: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           146: 
        !           147: --associative array--
        !           148: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           149: 
        !           150: --nested arrays--
        !           151: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           152: 
        !           153: --uppercase NULL--
        !           154: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           155: 
        !           156: --lowercase null--
        !           157: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           158: 
        !           159: --lowercase true--
        !           160: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           161: 
        !           162: --lowercase false--
        !           163: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           164: 
        !           165: --uppercase TRUE--
        !           166: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           167: 
        !           168: --uppercase FALSE--
        !           169: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           170: 
        !           171: --empty string DQ--
        !           172: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           173: 
        !           174: --empty string SQ--
        !           175: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           176: 
        !           177: --string DQ--
        !           178: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           179: 
        !           180: --string SQ--
        !           181: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           182: 
        !           183: --mixed case string--
        !           184: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           185: 
        !           186: --heredoc--
        !           187: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           188: 
        !           189: --instance of classWithToString--
        !           190: Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
        !           191: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           192: 
        !           193: --instance of classWithoutToString--
        !           194: Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
        !           195: string(32) "983d5edc5f77fe42e2372a0339dc22b0"
        !           196: 
        !           197: --undefined var--
        !           198: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           199: 
        !           200: --unset var--
        !           201: string(32) "5f781523f696d596e4b809d72197a0cc"
        !           202: 
        !           203: --resource--
        !           204: string(%d) %s
        !           205: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>