Пример #1
0
 /**
  * Tests UUID::v3()
  *
  * @test
  * @dataProvider provider_v3_md5
  * @covers UUID::v3
  * @param  string  $value     value to generate UUID from
  * @param  string  $expected  UUID
  */
 public function test_v3_md5($value, $expected)
 {
     $this->assertEquals($expected, UUID::v3(UUID::NIL, $value));
 }
Пример #2
0
/**
* 
*  getTempFilename - HelperFunction
* 
* @param string $url
* @param string $NS
* 
* @return
*/
function getTempFilename($url, $NS = '09c8637d-64f7-5eed-a80a-07a59059c47c')
{
    //1.3.6.1.4.1.37553.8.1.8.8.5.65.1
    return sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'download.zip.' . mt_rand(1000, 9999) . '.' . UUID::v3($NS, $url) . '.' . UUID::v5($NS, $url) . '.' . UUID::v4() . '.' . 'zip';
}
Пример #3
0
    {
        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
    }
    public static function v5($namespace, $name)
    {
        if (!self::is_valid($namespace)) {
            return false;
        }
        // Get hexadecimal components of namespace
        $nhex = str_replace(array('-', '{', '}'), '', $namespace);
        // Binary Value
        $nstr = '';
        // Convert Namespace UUID to bits
        for ($i = 0; $i < strlen($nhex); $i += 2) {
            $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
        }
        // Calculate hash value
        $hash = sha1($nstr . $name);
        return sprintf('%08s-%04s-%04x-%04x-%12s', substr($hash, 0, 8), substr($hash, 8, 4), hexdec(substr($hash, 12, 4)) & 0xfff | 0x5000, hexdec(substr($hash, 16, 4)) & 0x3fff | 0x8000, substr($hash, 20, 12));
    }
    public static function is_valid($uuid)
    {
        return preg_match('/^\\{?[0-9a-f]{8}\\-?[0-9a-f]{4}\\-?[0-9a-f]{4}\\-?' . '[0-9a-f]{4}\\-?[0-9a-f]{12}\\}?$/i', $uuid) === 1;
    }
}
// Usage
// Named-based UUID.
$v3uuid = UUID::v3('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString');
$v5uuid = UUID::v5('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString');
// Pseudo-random UUID
$v4uuid = UUID::v4();
Пример #4
0
<?php

namespace cd;

set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../core/');
require_once 'UUID.php';
$v3 = UUID::v3('514d2ee9-58ed-49ef-a592-1a49c268e2a2', 'test crap 123');
if ($v3 != "19d179a2-9511-3595-a8e2-490b981e92c2") {
    echo "FAIL 1\n";
}
$v5 = UUID::v5('514d2ee9-58ed-49ef-a592-1a49c268e2a2', 'test crap 123');
if ($v5 != "f1b18651-7633-5945-8527-853ddc5b6393") {
    echo "FAIL 2\n";
}
$v4 = UUID::v4();
echo "UUID v3 (md5):  " . $v3 . "\n";
echo "UUID v5 (sha1): " . $v5 . "\n";
echo "UUID v4 (rand): " . $v4 . "\n";
$hex = UUID::toHex('3F2504E0-4F89-11D3-9A0C-0305E82C3301');
if ($hex != 'E004253F894FD3119A0C0305E82C3301') {
    echo "FAIL 3\n";
}
    }
    public static function is_valid($uuid)
    {
        return preg_match('/^\\{?[0-9a-f]{8}\\-?[0-9a-f]{4}\\-?[0-9a-f]{4}\\-?' . '[0-9a-f]{4}\\-?[0-9a-f]{12}\\}?$/i', $uuid) === 1;
    }
}
/*********
LOGIC
*/
if (!empty($_GET["config"]) && $_GET["config"] == "email") {
    if (empty($_GET["email"]) || empty($_GET["gaspar"])) {
        die("Sorry, you did not provide your username and email address");
    }
    $content = $EPFL_EMAIL_CONFIG_PLIST_EN;
    if (!empty($_GET["lang"]) && $_GET["lang"] == "fr") {
        $content = $EPFL_EMAIL_CONFIG_PLIST_FR;
    }
    $IOS_EPFL_EMAIL_CONFIG_UUID = "ca8ea362-d121-45c1-9db4-a4e64b80f90c";
    $configuration_payload_uuid = UUID::v3($IOS_EPFL_EMAIL_CONFIG_UUID, "{$_GET["email"]} {$_GET["gaspar"]} configuration payload uuid");
    $account_payload_uuid = UUID::v3($IOS_EPFL_EMAIL_CONFIG_UUID, "{$_GET["email"]} {$_GET["gaspar"]} account payload uuid");
    header("Content-Type: application/x-apple-aspen-config");
    // ; charset=utf-8
    header('Content-Disposition: attachment; filename="EPFL_mail.mobileconfig"');
    $content = str_replace("USER_EMAIL", "{$_GET["email"]}", $content);
    $content = str_replace("USER_GASPAR", "{$_GET["gaspar"]}", $content);
    $content = str_replace("CONFIGURATION_PAYLOAD_UUID", "{$configuration_payload_uuid}", $content);
    $content = str_replace("ACCOUNT_PAYLOAD_UUID", "{$account_payload_uuid}", $content);
    echo "{$content}";
} else {
    die("Sorry, I don't know what you want to configure");
}