< Summary - Kestrun — Combined Coverage

Information
Class: Public.Certificate.New-KrSelfSignedCertificate
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Certificate/New-KrSelfSignedCertificate.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 60
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Certificate/New-KrSelfSignedCertificate.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Creates a new self-signed certificate.
 4    .DESCRIPTION
 5        The New-KrSelfSignedCertificate function generates a self-signed certificate for use in development or testing s
 6        This certificate can be used for securing communications or authentication purposes.
 7    .PARAMETER DnsNames
 8        The DNS name(s) for the certificate.
 9    .PARAMETER KeyType
 10        The type of key to use for the certificate (RSA or ECDSA).
 11    .PARAMETER KeyLength
 12        The length of the key in bits (only applicable for RSA).
 13    .PARAMETER ValidDays
 14        The number of days the certificate will be valid.
 15    .PARAMETER Ephemeral
 16        Indicates whether the certificate is ephemeral (temporary).
 17    .PARAMETER Exportable
 18        Indicates whether the private key is exportable.
 19    .EXAMPLE
 20        New-KrSelfSignedCertificate -Subject "CN=MyCert" -CertStoreLocation "Cert:\LocalMachine\My"
 21
 22        This example creates a self-signed certificate with the subject "CN=MyCert" and stores it in the local machine's
 23    .NOTES
 24        This function is intended for use in development and testing environments only. Do not use self-signed certifica
 25#>
 26function New-KrSelfSignedCertificate {
 27    [KestrunRuntimeApi('Everywhere')]
 28    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
 29    [CmdletBinding()]
 30    [OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
 31    param(
 32        [Parameter(Mandatory)]
 33        [string[]]$DnsNames,
 34
 35        [ValidateSet('Rsa', 'Ecdsa')]
 36        [string]$KeyType = 'Rsa',
 37
 38        [ValidateRange(256, 8192)]
 39        [int]$KeyLength = 2048,
 40
 41        [ValidateRange(1, 3650)]
 42        [int]$ValidDays = 365,
 43
 44        [switch]$Ephemeral,
 45        [switch]$Exportable
 46    )
 47
 148    $opts = [Kestrun.Certificates.CertificateManager+SelfSignedOptions]::new(
 49        $DnsNames,
 50        [Kestrun.Certificates.CertificateManager+KeyType]::$KeyType,
 51        $KeyLength,
 52        $null,      # purposes
 53        $ValidDays,
 54        $Ephemeral.IsPresent,
 55        $Exportable.IsPresent
 56    )
 57
 158    return [Kestrun.Certificates.CertificateManager]::NewSelfSigned($opts)
 59}
 60

Methods/Properties

New-KrSelfSignedCertificate()