You are here

public function VerifierB64Data::__construct in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/drupal/php-signify/src/VerifierB64Data.php \Drupal\Signify\VerifierB64Data::__construct()

File

vendor/drupal/php-signify/src/VerifierB64Data.php, line 13

Class

VerifierB64Data

Namespace

Drupal\Signify

Code

public function __construct($b64data, $length) {
  $decoded = base64_decode($b64data, true);
  $alg = substr($decoded, 0, 2);
  if ($alg !== self::PKALG) {
    throw new VerifierException(sprintf('Unexpected algorithm string %s', $alg));
  }
  $this->keyNum = substr($decoded, 2, self::KEYNUMLEN);
  $this->data = substr($decoded, 2 + self::KEYNUMLEN);
  if ($length !== SODIUM_CRYPTO_SIGN_BYTES && $length !== SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES) {
    throw new VerifierException(sprintf('Length must be %d or %d. Got %d', SODIUM_CRYPTO_SIGN_BYTES, SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES, $length));
  }
  if (strlen($this->data) !== $length) {
    throw new VerifierException('Data does not match expected length.');
  }
}