lib/mixlib/install/generator/powershell/scripts/helpers.ps1 in mixlib-install-1.0.0 vs lib/mixlib/install/generator/powershell/scripts/helpers.ps1 in mixlib-install-1.0.1
- old
+ new
@@ -58,21 +58,12 @@
function disposable($o){($o -is [IDisposable]) -and (($o | get-member | foreach-object {$_.name}) -contains 'Dispose')}
function use($obj, [scriptblock]$sb){try {& $sb} catch [exception]{throw $_} finally {if (disposable $obj) {$obj.Dispose()}} }
function Get-FileHash ($Path, $Algorithm) {
$Path = (resolve-path $path).providerpath
$hash = @{Algorithm = $Algorithm; Path = $Path}
- if ($Algorithm -like 'MD5') {
- use ($c = New-Object -TypeName Security.Cryptography.MD5CryptoServiceProvider) {
- use ($in = (gi $path).OpenRead()) {
- $hash.Hash = ([BitConverter]::ToString($c.ComputeHash($in))).Replace("-", "").ToUpper()
- }
- }
- }
- elseif ($Algorithm -like 'SHA256') {
- use ($c = New-Object -TypeName Security.Cryptography.SHA256CryptoServiceProvider) {
- use ($in = (gi $path).OpenRead()) {
- $hash.Hash = ([BitConverter]::ToString($c.ComputeHash($in))).Replace("-", "").ToUpper()
- }
+ use ($c = New-Object -TypeName Security.Cryptography.SHA256CryptoServiceProvider) {
+ use ($in = (gi $path).OpenRead()) {
+ $hash.Hash = ([BitConverter]::ToString($c.ComputeHash($in))).Replace("-", "").ToUpper()
}
}
new-object PSObject -Property $hash
}
}