public static function ParagonIE_Sodium_Compat::bin2base64 in Automatic Updates 7
Same name and namespace in other branches
- 8 vendor/paragonie/sodium_compat/src/Compat.php \ParagonIE_Sodium_Compat::bin2base64()
Parameters
string $decoded:
int $variant:
Return value
string
Throws
SodiumException
1 call to ParagonIE_Sodium_Compat::bin2base64()
- php72compat.php in vendor/
paragonie/ sodium_compat/ lib/ php72compat.php
File
- vendor/
paragonie/ sodium_compat/ src/ Compat.php, line 219
Class
Code
public static function bin2base64($decoded, $variant) {
/* Type checks: */
ParagonIE_Sodium_Core_Util::declareScalarType($decoded, 'string', 1);
/** @var string $decoded */
$decoded = (string) $decoded;
if (ParagonIE_Sodium_Core_Util::strlen($decoded) === 0) {
return '';
}
switch ($variant) {
case self::BASE64_VARIANT_ORIGINAL:
return ParagonIE_Sodium_Core_Base64_Original::encode($decoded);
case self::BASE64_VARIANT_ORIGINAL_NO_PADDING:
return ParagonIE_Sodium_Core_Base64_Original::encodeUnpadded($decoded);
case self::BASE64_VARIANT_URLSAFE:
return ParagonIE_Sodium_Core_Base64_UrlSafe::encode($decoded);
case self::BASE64_VARIANT_URLSAFE_NO_PADDING:
return ParagonIE_Sodium_Core_Base64_UrlSafe::encodeUnpadded($decoded);
default:
throw new SodiumException('invalid base64 variant identifier');
}
}