/// <summary> /// Checks if contents are valid /// </summary> /// <param name="throwArgumentException"></param> /// <returns>bool</returns> public static bool IsValid(this X509Thumbprint x509Thumbprint, bool throwArgumentException) { if (!x509Thumbprint.IsEmpty()) { bool primaryThumbprintIsValid = X509ThumbprintExtensions.IsValidThumbprint(x509Thumbprint.PrimaryThumbprint); bool secondaryThumbprintIsValid = X509ThumbprintExtensions.IsValidThumbprint(x509Thumbprint.SecondaryThumbprint); if (primaryThumbprintIsValid) { if (secondaryThumbprintIsValid || string.IsNullOrWhiteSpace(x509Thumbprint.SecondaryThumbprint)) { return(true); } else { if (throwArgumentException) { throw new ArgumentException(ApiResources.StringIsNotThumbprint.FormatInvariant(x509Thumbprint.SecondaryThumbprint), "Secondary Thumbprint"); } return(false); } } else if (secondaryThumbprintIsValid) { if (string.IsNullOrWhiteSpace(x509Thumbprint.PrimaryThumbprint)) { return(true); } else { if (throwArgumentException) { throw new ArgumentException(ApiResources.StringIsNotThumbprint.FormatInvariant(x509Thumbprint.PrimaryThumbprint), "PrimaryThumbprint"); } return(false); } } if (throwArgumentException) { if (string.IsNullOrEmpty(x509Thumbprint.SecondaryThumbprint)) { throw new ArgumentException(ApiResources.StringIsNotThumbprint.FormatInvariant(x509Thumbprint.PrimaryThumbprint), "Primary Thumbprint"); } else if (string.IsNullOrEmpty(x509Thumbprint.PrimaryThumbprint)) { throw new ArgumentException(ApiResources.StringIsNotThumbprint.FormatInvariant(x509Thumbprint.SecondaryThumbprint), "Secondary Thumbprint"); } else { throw new ArgumentException(ApiResources.StringIsNotThumbprint.FormatInvariant(x509Thumbprint.PrimaryThumbprint), "Primary Thumbprint"); } } } return(false); }
/// <summary> /// Checks if the thumbprints are populated /// </summary> /// <returns>bool</returns> public static bool IsEmpty(this X509Thumbprint x509Thumbprint) { return(string.IsNullOrWhiteSpace(x509Thumbprint.PrimaryThumbprint) && string.IsNullOrWhiteSpace(x509Thumbprint.SecondaryThumbprint)); }