public static bool IsValid()

in iothub/service/src/Registry/Models/X509ThumbprintExtensions.cs [25:94]


        public static bool IsValid(this X509Thumbprint x509Thumbprint, bool throwArgumentException)
        {
            if (!x509Thumbprint.IsEmpty())
            {
                int primaryThumbprintLength = x509Thumbprint.PrimaryThumbprint?.Length ?? 0;
                int secondaryThumbprintLength = x509Thumbprint.SecondaryThumbprint?.Length ?? 0;

                if (primaryThumbprintLength != secondaryThumbprintLength)
                {
                    if (primaryThumbprintLength != 0 && secondaryThumbprintLength != 0)
                    {
                        throw new ArgumentException(ApiResources.ThumbprintSizesMustMatch);
                    }
                }
                
                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;
        }