CLI_Command::validate_hashes
Method of the class: CLI_Command{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->validate_hashes( $file, $sha512_url, $md5_url );
- $file(string) (required)
- Release file path.
- $sha512_url(string) (required)
- URL to sha512 hash.
- $md5_url(string) (required)
- URL to md5 hash.
CLI_Command::validate_hashes() CLI Command::validate hashes code WP-CLI 2.13.0-alpha
private function validate_hashes( $file, $sha512_url, $md5_url ) {
$algos = [
'sha512' => $sha512_url,
'md5' => $md5_url,
];
foreach ( $algos as $algo => $url ) {
$response = Utils\http_request( 'GET', $url );
if ( '20' !== substr( $response->status_code, 0, 2 ) ) {
WP_CLI::log( "Couldn't access $algo hash for release (HTTP code {$response->status_code})." );
continue;
}
$file_hash = hash_file( $algo, $file );
$release_hash = trim( $response->body );
if ( $file_hash === $release_hash ) {
WP_CLI::log( "$algo hash verified: $release_hash" );
return;
} else {
WP_CLI::error( "$algo hash for download ($file_hash) is different than the release hash ($release_hash)." );
}
}
WP_CLI::error( 'Release hash verification failed.' );
}