Skip to content

Commit

Permalink
Show first 8 bytes of file in the hash check error message
Browse files Browse the repository at this point in the history
  • Loading branch information
r15ch13 committed Jul 9, 2018
1 parent e288e8c commit e4cbb42
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/install.ps1
Expand Up @@ -443,8 +443,9 @@ function hash_for_url($manifest, $url, $arch) {

# returns (ok, err)
function check_hash($file, $hash, $app_name) {
$file = fullpath $file
if(!$hash) {
warn "Warning: No hash in manifest. SHA256 is:`n $(compute_hash (fullpath $file) 'sha256')"
warn "Warning: No hash in manifest. SHA256 is:`n $(compute_hash $file) 'sha256')"
return $true, $null
}

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

$actual = compute_hash (fullpath $file) $type

$actual = (compute_hash $file $type).ToLower()
$expected = $expected.ToLower()
$actual = $actual.ToLower()

if($actual -ne $expected) {
$msg = "Hash check failed!`n"
$msg += "App: $app_name`n"
$msg += "URL: $url`n"
$msg += "App: $app_name`n"
$msg += "URL: $url`n"
if(Test-Path $file) {
$hexbytes = Get-Content $file -Encoding byte -TotalCount 8 | ForEach-Object { $_.tostring('x2') }
$hexbytes = [string]::join(' ', $hexbytes).ToUpper()
$msg += "First bytes: $hexbytes`n"
}
if($expected -or $actual) {
$msg += "Expected: $expected`n"
$msg += "Actual: $actual"
$msg += "Expected: $expected`n"
$msg += "Actual: $actual"
}
return $false, $msg
}
Expand Down

0 comments on commit e4cbb42

Please sign in to comment.