From 8cab0aeac6377d2f2ffe2277c60a9feea84f4e4b Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 14 Jun 2022 09:10:38 +0200 Subject: [PATCH] update pwsh style in certificate files --- src/Certificate/Get-CSCertificate.ps1 | 18 ++++-------- src/Certificate/Import-CSCertificate.ps1 | 12 ++------ src/Certificate/New-CSCertAttribute.ps1 | 17 +++-------- src/Certificate/New-CSCertificate.ps1 | 12 ++------ src/Certificate/Test-CSCertificate.ps1 | 11 ++------ src/Certificate/Use-CSCertificate.ps1 | 36 +++++++++--------------- 6 files changed, 30 insertions(+), 76 deletions(-) diff --git a/src/Certificate/Get-CSCertificate.ps1 b/src/Certificate/Get-CSCertificate.ps1 index 5bb654b..1898234 100644 --- a/src/Certificate/Get-CSCertificate.ps1 +++ b/src/Certificate/Get-CSCertificate.ps1 @@ -20,18 +20,11 @@ function Get-CSCertificate { .EXAMPLE Get-CSCertificate -Type 'Shared' -Thumbprint '12334456' - - .NOTES - - File Name : Get-CSCertificate.ps1 - - Author : Marco Blessing - marco.blessing@googlemail.com - - Requires : - - .LINK - https://github.com/OCram85/PSCredentialStore #> + [CmdletBinding()] [OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])] - param( + param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [ValidateSet('Private', 'Shared')] @@ -42,8 +35,8 @@ function Get-CSCertificate { [string]$Thumbprint ) - begin { - } + begin {} + process { if ($Type -eq 'Private') { Get-CSPfXCertificate -Thumbprint $Thumbprint -StoreName 'My' -StoreLocation 'CurrentUser' @@ -69,6 +62,5 @@ function Get-CSCertificate { } } } - end { - } + end {} } diff --git a/src/Certificate/Import-CSCertificate.ps1 b/src/Certificate/Import-CSCertificate.ps1 index 244eb63..fc391c2 100644 --- a/src/Certificate/Import-CSCertificate.ps1 +++ b/src/Certificate/Import-CSCertificate.ps1 @@ -21,18 +21,10 @@ function Import-CSCertificate { .EXAMPLE Import-CSCertificate -Type 'Private' -Path (Join-Path -Path $Env:APPDATA -ChildItem 'PfxCertificate.pfx') - - .NOTES - - File Name : Import-CSCertificate.ps1 - - Author : Marco Blessing - marco.blessing@googlemail.com - - Requires : - - .LINK - https://github.com/OCram85/PSCredentialStore #> + [CmdletBinding()] - [OutputType()] - param( + param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [ValidateSet('Private', 'Shared')] diff --git a/src/Certificate/New-CSCertAttribute.ps1 b/src/Certificate/New-CSCertAttribute.ps1 index e199a83..ab77fd6 100644 --- a/src/Certificate/New-CSCertAttribute.ps1 +++ b/src/Certificate/New-CSCertAttribute.ps1 @@ -35,18 +35,11 @@ function New-CSCertAttribute { .EXAMPLE New-CSCertAttribute -Country 'DE' -State 'BW' -City 'Karlsruhe' -Organization 'AwesomeIT' -OrganizationalUnitName '' -CommonName 'MyPrivateCert' - - .NOTES - - File Name : New-CSCertAttribute.ps1 - - Author : Marco Blessing - marco.blessing@googlemail.com - - Requires : - - .LINK - https://github.com/OCram85/PSCredentialStore #> + [CmdletBinding()] [OutputType('PSCredentialStore.Certificate.Attribute')] - param( + param ( [Parameter(Mandatory = $true)] [ValidateLength(2, 2)] [ValidateNotNull()] @@ -76,9 +69,8 @@ function New-CSCertAttribute { [ValidateNotNull()] [int]$Days = 365 ) - begin { + begin {} - } process { return [PSCustomObject]@{ PSTypeName = 'PSCredentialStore.Certificate.Attribute' @@ -94,6 +86,5 @@ function New-CSCertAttribute { Days = $Days } } - end { - } + end {} } diff --git a/src/Certificate/New-CSCertificate.ps1 b/src/Certificate/New-CSCertificate.ps1 index 91d5554..6e93ef0 100644 --- a/src/Certificate/New-CSCertificate.ps1 +++ b/src/Certificate/New-CSCertificate.ps1 @@ -23,18 +23,11 @@ function New-CSCertificate { .EXAMPLE New-CSCertificate -CRTAttribute $CRTAttribute -KeyName './myprivate.key' -CertName './mycert.pfx' - - .NOTES - - File Name : New-CSCertificate.ps1 - - Author : Marco Blessing - marco.blessing@googlemail.com - - Requires : - - .LINK - https://github.com/OCram85/PSCredentialStore #> + [CmdletBinding(SupportsShouldProcess = $true)] [OutputType()] - param( + param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [PSTypeName('PSCredentialStore.Certificate.Attribute')]$CRTAttribute, @@ -70,6 +63,7 @@ function New-CSCertificate { $Env:OPENSSL_CONF = Join-Path $ModuleBase -ChildPath '/openssl.conf' } + process { $SubjPattern = "/C={0}/ST={1}/L={2}/O={3}/OU={4}/CN={5}" $SubjValues = @( diff --git a/src/Certificate/Test-CSCertificate.ps1 b/src/Certificate/Test-CSCertificate.ps1 index 4ef34f6..eee291c 100644 --- a/src/Certificate/Test-CSCertificate.ps1 +++ b/src/Certificate/Test-CSCertificate.ps1 @@ -17,17 +17,10 @@ function Test-CSCertificate { .EXAMPLE Test-CSCertificate -Type 'Shared' - - .NOTES - - File Name : Test-CSCertificate.ps1 - - Author : Marco Blessing - marco.blessing@googlemail.com - - Requires : - - .LINK - https://github.com/OCram85/PSCredentialStore #> + [CmdletBinding()] - [OutputType([bool])] + [OutputType([boolean])] param( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/src/Certificate/Use-CSCertificate.ps1 b/src/Certificate/Use-CSCertificate.ps1 index 76f0f40..0bd993b 100644 --- a/src/Certificate/Use-CSCertificate.ps1 +++ b/src/Certificate/Use-CSCertificate.ps1 @@ -26,36 +26,28 @@ function Use-CSCertificate { .EXAMPLE Use-CSCertificate -Path 'C:\cert.pfx' - - .NOTES - File Name : Use-CSCertificate.ps1 - Author : Marco Blessing - marco.blessing@googlemail.com - Requires : - - .LINK - https://github.com/OCram85/PSCredentialStore #> - [CmdletBinding(DefaultParameterSetName = "Private")] - [OutputType()] + + [CmdletBinding(DefaultParameterSetName = 'Private')] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] - param( - [Parameter(Mandatory = $true, ParameterSetName = "Private")] - [Parameter(Mandatory = $true, ParameterSetName = "Shared")] + param ( + [Parameter(Mandatory = $true, ParameterSetName = 'Private')] + [Parameter(Mandatory = $true, ParameterSetName = 'Shared')] [ValidateNotNullOrEmpty()] [string]$Path, - [Parameter(Mandatory = $false, ParameterSetName = "Shared")] + [Parameter(Mandatory = $false, ParameterSetName = 'Shared')] [ValidateNotNullOrEmpty()] [string]$CredentialStore, - [Parameter(Mandatory = $true, ParameterSetName = "Shared")] + [Parameter(Mandatory = $true, ParameterSetName = 'Shared')] [switch]$Shared, - [Parameter(Mandatory = $false, ParameterSetName = "Private")] - [Parameter(Mandatory = $false, ParameterSetName = "Shared")] - [Switch]$UseCertStore + [Parameter(Mandatory = $false, ParameterSetName = 'Private')] + [Parameter(Mandatory = $false, ParameterSetName = 'Shared')] + [switch]$UseCertStore ) - begin { } + begin {} process { try { @@ -74,11 +66,11 @@ function Use-CSCertificate { } try { - if ($PSCmdlet.ParameterSetName -eq "Private") { + if ($PSCmdlet.ParameterSetName -eq 'Private') { $StorePath = Get-DefaultCredentialStorePath $CS = Get-CredentialStore } - elseif ($PSCmdlet.ParameterSetName -eq "Shared" ) { + elseif ($PSCmdlet.ParameterSetName -eq 'Shared' ) { if (!($PSBoundParameters.ContainsKey('CredentialStore'))) { $StorePath = Get-DefaultCredentialStorePath -Shared $CS = Get-CredentialStore -Shared @@ -117,5 +109,5 @@ Make sure you used the same AES keys for encrypting! $CS | ConvertTo-Json -Depth 5 | Out-File -FilePath $StorePath -Force -Encoding utf8 } - end { } + end {} }