You are here

public function ChecksumList::__construct in Automatic Updates 7

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

File

vendor/drupal/php-signify/src/ChecksumList.php, line 14

Class

ChecksumList

Namespace

Drupal\Signify

Code

public function __construct($checksum_list_raw, $list_is_trusted) {
  $lines = explode("\n", $checksum_list_raw);
  foreach ($lines as $line) {
    if (trim($line) == '') {
      continue;
    }
    if (substr($line, 0, 1) === '\\') {
      throw new VerifierException('Filenames with problematic characters are not yet supported.');
    }
    $algo = substr($line, 0, strpos($line, ' '));
    if (empty($this->HASH_ALGO_BASE64_LENGTHS[$algo])) {
      throw new VerifierException("Algorithm \"{$algo}\" is unsupported for checksum verification.");
    }
    $filename_start = strpos($line, '(') + 1;
    $bytes_after_filename = $this->HASH_ALGO_BASE64_LENGTHS[$algo] + 4;
    $filename = substr($line, $filename_start, -$bytes_after_filename);
    $this->checksums[] = new VerifierFileChecksum($filename, $algo, substr($line, -$this->HASH_ALGO_BASE64_LENGTHS[$algo]), $list_is_trusted);
  }
}