/// <summary> /// Validate the current curve. /// </summary> /// <exception cref="CryptographicException"> /// if the curve parameters are not valid for the current CurveType. /// </exception> public void Validate() { if (IsNamed) { if (HasAnyExplicitParameters()) { throw new CryptographicException(SR.Cryptography_InvalidECNamedCurve); } if (Oid == null || (string.IsNullOrEmpty(Oid.FriendlyName) && string.IsNullOrEmpty(Oid.Value))) { throw new CryptographicException(SR.Cryptography_InvalidCurveOid); } } else if (IsExplicit) { bool hasErrors = false; if (A == null || B == null || B.Length != A.Length || G.X == null || G.X.Length != A.Length || G.Y == null || G.Y.Length != A.Length || Order == null || Order.Length == 0 || Cofactor == null || Cofactor.Length == 0) { hasErrors = true; } if (IsPrime) { if (!hasErrors) { if (Prime == null || Prime.Length != A.Length) { hasErrors = true; } } if (hasErrors) { throw new CryptographicException(SR.Cryptography_InvalidECPrimeCurve); } } else if (IsCharacteristic2) { if (!hasErrors) { if (Polynomial == null || Polynomial.Length == 0) { hasErrors = true; } } if (hasErrors) { throw new CryptographicException(SR.Cryptography_InvalidECCharacteristic2Curve); } } } else { // Implicit; if there are any values, throw Debug.Assert(CurveType == ECCurveType.Implicit); if (HasAnyExplicitParameters() || Oid != null) { throw new CryptographicException(SR.Format(SR.Cryptography_CurveNotSupported, CurveType.ToString())); } } }
/// <summary> /// Validate the current curve. /// </summary> /// <exception cref="CryptographicException"> /// The curve parameters are not valid for the current <see cref="CurveType"/>. /// </exception> public void Validate() { if (IsNamed) { if (HasAnyExplicitParameters()) { throw new CryptographicException(CryptographicInvalidNamedCurve); } if (Oid == null || (string.IsNullOrEmpty(Oid.FriendlyName) && string.IsNullOrEmpty(Oid.Value))) { throw new CryptographicException(CryptographicInvalidCurveOid); } } else if (IsExplicit) { bool hasErrors = HasCommonExplicitCurveErrors(); if (IsPrime) { if (!hasErrors) { if (Prime == null || Prime.Length != A.Length) { hasErrors = true; } } if (hasErrors) { throw new CryptographicException(CryptographicInvalidPrimeCurve); } } else if (IsCharacteristic2) { if (!hasErrors) { if (Polynomial == null || Polynomial.Length == 0) { hasErrors = true; } } if (hasErrors) { throw new CryptographicException(CryptographicInvalidCharacteristic2Curve); } } } else { // Implicit; if there are any values, throw if (HasAnyExplicitParameters() || Oid != null) { throw new CryptographicException(string.Format(Culture, CryptographicCurveNotSupported, CurveType.ToString())); } } }