<commit_before>﻿//
// SaslMechanism.cs
//
// Author: <NAME> <<EMAIL>>
//
// Copyright (c) 2013-2022 .NET Foundation and Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using System;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Security.Authentication.ExtendedProtection;

using MailKit.Net;

#if NETSTANDARD1_3 || NETSTANDARD1_6
using MD5 = MimeKit.Cryptography.MD5;
#endif

namespace MailKit.Security {
	/// <summary>
	/// A SASL authentication mechanism.
	/// </summary>
	/// <remarks>
	/// Authenticating via a SASL mechanism may be a multi-step process.
	/// To determine if the mechanism has completed the necessary steps
	/// to authentication, check the <see cref="IsAuthenticated"/> after
	/// each call to <see cref="Challenge(string,CancellationToken)"/>.
	/// </remarks>
	public abstract class SaslMechanism
	{
		/// <summary>
		/// The supported authentication mechanisms in order of strongest to weakest.
		/// </summary>
		/// <remarks>
		/// <para>Used by the various clients when authenticating via SASL to determine
		/// which order the SASL mechanisms supported by the server should be tried.</para>
		/// <note type="note">Even though NTLM is more secure than PLAIN or LOGIN (and
		/// probably others), it is tried last only because it is less reliable due to
		/// missing functionality to make it 100% compatible with all NTLM server
		/// implementations.</note>
		/// </remarks>
		static readonly string[] RankedAuthenticationMechanisms;
		static readonly bool md5supported;

		static SaslMechanism ()
		{
			try {
				using (var md5 = MD5.Create ())
					md5supported = true;
			} catch {
				md5supported = false;
			}

			// Note: It's probably arguable that NTLM is more secure than SCRAM but the odds of a server supporting both is probably low.<commit_msg>Remove obsolete note about NTLM<commit_after>﻿//
// SaslMechanism.cs
//
// Author: <NAME> <<EMAIL>>
//
// Copyright (c) 2013-2022 .NET Foundation and Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using System;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Security.Authentication.ExtendedProtection;

using MailKit.Net;

#if NETSTANDARD1_3 || NETSTANDARD1_6
using MD5 = MimeKit.Cryptography.MD5;
#endif

namespace MailKit.Security {
	/// <summary>
	/// A SASL authentication mechanism.
	/// </summary>
	/// <remarks>
	/// Authenticating via a SASL mechanism may be a multi-step process.
	/// To determine if the mechanism has completed the necessary steps
	/// to authentication, check the <see cref="IsAuthenticated"/> after
	/// each call to <see cref="Challenge(string,CancellationToken)"/>.
	/// </remarks>
	public abstract class SaslMechanism
	{
		/// <summary>
		/// The supported authentication mechanisms in order of strongest to weakest.
		/// </summary>
		/// <remarks>
		/// <para>Used by the various clients when authenticating via SASL to determine
		/// which order the SASL mechanisms supported by the server should be tried.</para>
		/// </remarks>
		static readonly string[] RankedAuthenticationMechanisms;
		static readonly bool md5supported;

		static SaslMechanism ()
		{
			try {
				using (var md5 = MD5.Create ())
					md5supported = true;
			} catch {
				md5supported = false;
			}

			// Note: It's probably arguable that NTLM is more secure than SCRAM but the odds of a server supporting both is probably low.
{'fraction_non_alphanumeric': 0.09365079365079365, 'fraction_numerical': 0.007231040564373898, 'mean_word_length': 3.614320585842148, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3496770', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1498, 'n_words': 689}