Exemplo n.º 1
0
 /**
  * Create a version 5 UUID based upon a name and a given namespace
  *
  * @param   util.UUID namespace
  * @param   string name
  * @return  util.UUID
  */
 public static function sha1UUID(self $namespace, $name)
 {
     $bytes = sha1($namespace->getBytes() . iconv(\xp::ENCODING, 'utf-8', $name));
     return new self([5, hexdec(substr($bytes, 0, 8)), hexdec(substr($bytes, 8, 4)), hexdec(substr($bytes, 12, 4)) & 0xfff, hexdec(substr($bytes, 16, 4)) & 0x3fff | 0x8000, array_map('hexdec', str_split(substr($bytes, 20, 12), 2))]);
 }
Exemplo n.º 2
0
 public function sha1ExampleDotComWithDnsNs()
 {
     $this->assertEquals('cfbff0d1-9375-5685-968c-48ce8b15ae17', UUID::sha1UUID(UUID::$NS_DNS, 'example.com')->hashCode());
 }