Private/Get-SqlCaCertificate.ps1
|
# ============================================================================= # Script : Private/Get-SqlCaCertificate.ps1 # Author : Keith Ramsey # Created : 2026-09-08 # ============================================================================= # D1/A1 helper (GR-003, DR-034): load an X509 certificate from a .cer file so the # client-trust commands can read its thumbprint/subject/expiry and raw bytes. The # one mockable seam for file loading; may throw on a bad file -- the calling # command's never-throw wrapper turns that into a Failed result. # ============================================================================= function Get-SqlCaCertificate { <# .SYNOPSIS Loads an X509 certificate from a file (the issuer/root to distribute). A1 helper. .DESCRIPTION Reads a certificate (.cer, DER or Base64) from disk and returns the X509Certificate2. A single seam so the client-trust commands can be unit-tested by mocking this function. .PARAMETER Path Path to the certificate file. .OUTPUTS System.Security.Cryptography.X509Certificates.X509Certificate2 .NOTES Steps: 1. Load the X509 certificate from the file and return it (throws on a bad/absent file; the caller catches). #> [CmdletBinding()] [OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])] param( [Parameter(Mandatory)] [string] $Path ) # 1. Load (may throw; the caller's never-throw wrapper reports a Failed result). [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($Path) } |