Skip to content

Commit

Permalink
moving crypto to use dll from nuget instead of gac #82 #81 #80
Browse files Browse the repository at this point in the history
  • Loading branch information
sayedihashimi committed Oct 24, 2016
1 parent 7b2b5ca commit f320efa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
13 changes: 7 additions & 6 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,16 @@ function Update-Dependencies{
# restore the packages to that folder
'Getting latest file-replacer' | Write-Output
$fpPath = Get-NuGetPackage -name 'file-replacer' -prerelease -cachePath $tempFolder -binpath

'Getting latest nuget-powershell' | Write-Output
$npPath = Get-NuGetPackage -name 'nuget-powershell' -prerelease -cachePath $tempFolder -binpath

#move the files to the dest dir
Copy-Item -path "$fpPath\*.ps*1" -Destination "$destDir"
Copy-Item -path "$fpPath\*.dll" -Destination "$destDir"

Copy-Item -path "$npPath\*.ps*1" -Destination "$destDir"
'Getting latest nuget-powershell' | Write-Output
$npPath = Get-NuGetPackage -name 'nuget-powershell' -prerelease -cachePath $tempFolder -binpath
Copy-Item -path "$npPath\*.dll" -Destination "$destDir"

'Getting latest System.Security.Cryptography.Primitives.dll' | Write-Output
$cryptoPath = (Get-NugetPackage -name 'System.Security.Cryptography.Algorithms' -version '4.2.0' -binpath)
Copy-Item -Path "$cryptoPath\netstandard1.3\System.Security.Cryptography.Primitives.dll" -Destination $destDir
}
}

Expand Down
Binary file not shown.
38 changes: 36 additions & 2 deletions src/psbuild.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ $global:PSBuildSettings = New-Object PSObject -Property @{
EnableMaskLogFiles = $true
EnableAddingHashToLogDir = $true
ContribDirs = @($scriptDir,(Join-Path $scriptDir '..\contrib\'))
LoadedCryptoApi = $false
}

function InternalOverrideSettingsFromEnv{
Expand Down Expand Up @@ -1008,15 +1009,17 @@ Function Get-StringHash{
[String] $text,
$HashName = "MD5"
)
begin{
InternalLoad-CryptoApi
}
process{
$sb = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($text))|%{
[System.Security.Cryptography.MD5CryptoServiceProvider]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($text))|%{
[Void]$sb.Append($_.ToString("x2"))
}
$sb.ToString()
}
}

function Open-PSBuildLogDirectory{
[cmdletbinding()]
param()
Expand Down Expand Up @@ -2340,6 +2343,37 @@ function Import-NuGetPowershell{
}
}

function InternalLoad-CryptoApi{
[cmdletbinding()]
param()
process{
[bool]$foundIt = $false
if($global:PSBuildSettings.LoadedCryptoApi -ne $true){
foreach($path in $global:PSBuildSettings.ContribDirs){
$dllpath = (get-fullpath (Join-Path $path 'System.Security.Cryptography.Primitives.dll'))
if(Test-Path $dllpath){
try{
Add-type -Path $dllpath
$foundIt = $true
break
}
catch
{
$_.LoaderExceptions | %
{
Write-Error 'LoaderExceptions: ' + $_.Message
}
}
}
}

if(-not $foundIt){
'Did not find System.Security.Cryptography.Primitives.dll' | Write-Warning
}
}
}
}

<#
.SYNOPSIS
This will download and import the given version of file-replacer (https://github.com/ligershark/template-builder/blob/master/file-replacer.psm1),
Expand Down

0 comments on commit f320efa

Please sign in to comment.