urbit/kats/check-sums.ps1
Paul Driver aa02d49a22 Squashed 'pkg/urcrypt/argon2/' content from commit 4da94a611
git-subtree-dir: pkg/urcrypt/argon2
git-subtree-split: 4da94a611ee62bad87ab2b131ffda3bcc0723d9c
2020-10-03 15:18:53 -07:00

43 lines
1.2 KiB
PowerShell

Set-Variable tempfile -option Constant -value "tempfile"
function hash($path) {
$fullPath = Resolve-Path $path
$hash = new-object -TypeName System.Security.Cryptography.SHA256CryptoServiceProvider
$contents = [IO.File]::ReadAllText($fullPath) -replace "`r`n?", "`n"
# create UTF-8 encoding without signature
$utf8 = New-Object System.Text.UTF8Encoding $false
# write the text back
[IO.File]::WriteAllText($tempfile, $contents, $utf8)
$file = [System.IO.File]::Open($tempfile,[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
$result = [System.BitConverter]::ToString($hash.ComputeHash($file))
$file.Dispose()
if (Test-Path $tempfile) {
Remove-Item $tempfile
}
return $result
}
function main() {
$files = $(Get-ChildItem * | Where-Object { $_.Name -match '^[a-z2]*(_v)?[0-9]*$' } | select -ExpandProperty name)
foreach ($file in $files) {
$new = $(hash $file).replace("-","")
$new = $new.ToLower()
$old=$(Get-Content $file".shasum")
$old = $old.Substring(0, $old.IndexOf(" "))
if ($new -eq $old) {
Write-Host $file "`tOK"
} else {
Write-Host $file "`tERROR"
}
}
}
main