You are here

public static function ParagonIE_Sodium_Compat::base642bin in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Compat.php \ParagonIE_Sodium_Compat::base642bin()

Parameters

string $encoded:

int $variant:

string $ignore:

Return value

string

Throws

SodiumException

1 call to ParagonIE_Sodium_Compat::base642bin()
php72compat.php in vendor/paragonie/sodium_compat/lib/php72compat.php

File

vendor/paragonie/sodium_compat/src/Compat.php, line 176

Class

ParagonIE_Sodium_Compat

Code

public static function base642bin($encoded, $variant, $ignore = '') {

  /* Type checks: */
  ParagonIE_Sodium_Core_Util::declareScalarType($encoded, 'string', 1);

  /** @var string $encoded */
  $encoded = (string) $encoded;
  if (ParagonIE_Sodium_Core_Util::strlen($encoded) === 0) {
    return '';
  }

  // Just strip before decoding
  if (!empty($ignore)) {
    $encoded = str_replace($ignore, '', $encoded);
  }
  try {
    switch ($variant) {
      case self::BASE64_VARIANT_ORIGINAL:
        return ParagonIE_Sodium_Core_Base64_Original::decode($encoded, true);
      case self::BASE64_VARIANT_ORIGINAL_NO_PADDING:
        return ParagonIE_Sodium_Core_Base64_Original::decode($encoded, false);
      case self::BASE64_VARIANT_URLSAFE:
        return ParagonIE_Sodium_Core_Base64_UrlSafe::decode($encoded, true);
      case self::BASE64_VARIANT_URLSAFE_NO_PADDING:
        return ParagonIE_Sodium_Core_Base64_UrlSafe::decode($encoded, false);
      default:
        throw new SodiumException('invalid base64 variant identifier');
    }
  } catch (Exception $ex) {
    if ($ex instanceof SodiumException) {
      throw $ex;
    }
    throw new SodiumException('invalid base64 string');
  }
}