|
@@ 49-59 (lines=11) @@
|
| 46 |
|
return new GUID($binStr); |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
public static function fromHexString(string $hexStr, int $expectedLength = self::DEFAULT_GUID_SIZE): GUID |
| 50 |
|
{ |
| 51 |
|
if (0 === \preg_match('/^(([0-9A-F]{2})+|([0-9a-f]{2})+)$/', $hexStr)) { |
| 52 |
|
throw new UnserializationError('Invalid hexadecimal string'); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
return self::fromBinaryString( |
| 56 |
|
\hex2bin($hexStr), |
| 57 |
|
$expectedLength |
| 58 |
|
); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public static function fromBase64String(string $b64Str, int $expectedLength = self::DEFAULT_GUID_SIZE): GUID |
| 62 |
|
{ |
|
@@ 61-71 (lines=11) @@
|
| 58 |
|
); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public static function fromBase64String(string $b64Str, int $expectedLength = self::DEFAULT_GUID_SIZE): GUID |
| 62 |
|
{ |
| 63 |
|
if (0 === \preg_match('#^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$#', $b64Str)) { |
| 64 |
|
throw new UnserializationError('Invalid base64 string'); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
return self::fromBinaryString( |
| 68 |
|
\base64_decode($b64Str, true), |
| 69 |
|
$expectedLength |
| 70 |
|
); |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
public static function fromBase64UrlString(string $b64Str, int $expectedLength = self::DEFAULT_GUID_SIZE): GUID |
| 74 |
|
{ |
|
@@ 73-83 (lines=11) @@
|
| 70 |
|
); |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
public static function fromBase64UrlString(string $b64Str, int $expectedLength = self::DEFAULT_GUID_SIZE): GUID |
| 74 |
|
{ |
| 75 |
|
if (0 === \preg_match('#^(?:[A-Za-z0-9\-_]{4})*(?:[A-Za-z0-9\-_]{2}\.\.|[A-Za-z0-9\-_]{3}\.)?$#', $b64Str)) { |
| 76 |
|
throw new UnserializationError('Invalid base64 string'); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
return self::fromBase64String( |
| 80 |
|
\strtr($b64Str, '-_.', '+/='), |
| 81 |
|
$expectedLength |
| 82 |
|
); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
public function asBinaryString(): string |
| 86 |
|
{ |