| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Combines multiple X509KeyUsageFlags into a single value. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | The Join-KeyUsageFlag function takes an array of X509KeyUsageFlags and combines them using a bitwise OR operation to |
| | | 6 | | that represents all the specified key usage flags. |
| | | 7 | | This is useful for scenarios where multiple key usage flags need to be included in a certificate request or self-sig |
| | | 8 | | and the underlying APIs expect a single combined value rather than an array of individual flags. |
| | | 9 | | .PARAMETER KeyUsage |
| | | 10 | | An array of X509KeyUsageFlags to combine. Each element in the array should be a valid X509KeyUsageFlags value such a |
| | | 11 | | .OUTPUTS |
| | | 12 | | [System.Security.Cryptography.X509Certificates.X509KeyUsageFlags] - A single combined X509KeyUsageFlags value that r |
| | | 13 | | If no valid flags are provided, it returns $null. |
| | | 14 | | .EXAMPLE |
| | | 15 | | $combinedFlags = Join-KeyUsageFlag -KeyUsage DigitalSignature, KeyEncipherment |
| | | 16 | | Write-Output $combinedFlags |
| | | 17 | | |
| | | 18 | | This example combines the DigitalSignature and KeyEncipherment flags into a single X509KeyUsageFlags value and outpu |
| | | 19 | | .EXAMPLE |
| | | 20 | | $combinedFlags = Join-KeyUsageFlag -KeyUsage DataEncipherment, KeyAgreement |
| | | 21 | | Write-Output $combinedFlags |
| | | 22 | | |
| | | 23 | | This example combines the DataEncipherment and KeyAgreement flags into a single X509KeyUsageFlags value and outputs |
| | | 24 | | #> |
| | | 25 | | function Join-KeyUsageFlag { |
| | | 26 | | param( |
| | | 27 | | [System.Security.Cryptography.X509Certificates.X509KeyUsageFlags[]]$KeyUsage |
| | | 28 | | ) |
| | | 29 | | |
| | 1 | 30 | | $combinedKeyUsage = [System.Security.Cryptography.X509Certificates.X509KeyUsageFlags]::None |
| | | 31 | | |
| | 1 | 32 | | foreach ($keyUsageFlag in $KeyUsage) { |
| | 1 | 33 | | $combinedKeyUsage = $combinedKeyUsage -bor $keyUsageFlag |
| | | 34 | | } |
| | | 35 | | |
| | 1 | 36 | | if ($combinedKeyUsage -eq [System.Security.Cryptography.X509Certificates.X509KeyUsageFlags]::None) { |
| | 0 | 37 | | return $null |
| | | 38 | | } |
| | | 39 | | |
| | 1 | 40 | | return $combinedKeyUsage |
| | | 41 | | } |