Skip to content

Commit e4cbb42

Browse files
committed
Show first 8 bytes of file in the hash check error message
1 parent e288e8c commit e4cbb42

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

lib/install.ps1

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,9 @@ function hash_for_url($manifest, $url, $arch) {
443443

444444
# returns (ok, err)
445445
function check_hash($file, $hash, $app_name) {
446+
$file = fullpath $file
446447
if(!$hash) {
447-
warn "Warning: No hash in manifest. SHA256 is:`n $(compute_hash (fullpath $file) 'sha256')"
448+
warn "Warning: No hash in manifest. SHA256 is:`n $(compute_hash $file) 'sha256')"
448449
return $true, $null
449450
}
450451

@@ -459,18 +460,21 @@ function check_hash($file, $hash, $app_name) {
459460
return $false, "Hash type '$type' isn't supported."
460461
}
461462

462-
$actual = compute_hash (fullpath $file) $type
463-
463+
$actual = (compute_hash $file $type).ToLower()
464464
$expected = $expected.ToLower()
465-
$actual = $actual.ToLower()
466465

467466
if($actual -ne $expected) {
468467
$msg = "Hash check failed!`n"
469-
$msg += "App: $app_name`n"
470-
$msg += "URL: $url`n"
468+
$msg += "App: $app_name`n"
469+
$msg += "URL: $url`n"
470+
if(Test-Path $file) {
471+
$hexbytes = Get-Content $file -Encoding byte -TotalCount 8 | ForEach-Object { $_.tostring('x2') }
472+
$hexbytes = [string]::join(' ', $hexbytes).ToUpper()
473+
$msg += "First bytes: $hexbytes`n"
474+
}
471475
if($expected -or $actual) {
472-
$msg += "Expected: $expected`n"
473-
$msg += "Actual: $actual"
476+
$msg += "Expected: $expected`n"
477+
$msg += "Actual: $actual"
474478
}
475479
return $false, $msg
476480
}

0 commit comments

Comments
 (0)