using Org.BouncyCastle.Crypto; using PKISharp.WACS.Plugins.Interfaces; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace PKISharp.WACS.DomainObjects { [DebuggerDisplay("Target: {CommonName} ({Parts.Count} part(s) - IIS: {IIS})")] public class Target { public Target(string friendlyName, string commonName, IEnumerable parts) { FriendlyName = friendlyName; CommonName = commonName; Parts = parts; } /// /// Suggest a FriendlyName for the certificate, /// but this may be overruled by the user /// public string? FriendlyName { get; set; } /// /// CommonName for the certificate /// public string CommonName { get; private set; } /// /// Different parts that make up this target /// public IEnumerable Parts { get; private set; } /// /// Check if all parts are IIS /// public bool IIS => Parts.All(x => x.IIS); /// /// The CSR used to request the certificate /// public byte[]? CsrBytes { get; set; } /// /// The Private Key corresponding to the CSR /// public AsymmetricKeyParameter? PrivateKey { get; set; } /// /// Pretty print information about the target /// /// public override string ToString() { var x = new StringBuilder(); x.Append(CommonName); var alternativeNames = Parts.SelectMany(p => p.Identifiers).Distinct(); if (alternativeNames.Count() > 1) { x.Append($" and {alternativeNames.Count() - 1} alternatives"); } return x.ToString(); } } [DebuggerDisplay("Target: null")] public class NullTarget : Target, INull { public NullTarget() : base("", "", new List()) { } } }