/// <summary> /// Returns a new set of plain credentials. /// </summary> /// <param name="pUserId"></param> /// <param name="pPassword"></param> /// <param name="pTLSRequirement">The TLS requirement for the credentials to be used.</param> /// <param name="pTryAuthenticateEvenIfPlainIsntAdvertised">Indicates whether the SASL PLAIN mechanism should be tried even if not advertised.</param> /// <returns></returns> /// <remarks> /// The credentials returned may fall back to IMAP LOGIN if SASL PLAIN isn't available. /// This method will throw if the userid and password can be used in neither <see cref="cLogin"/> nor <see cref="cSASLPlain"/>. /// </remarks> public static cCredentials Plain(string pUserId, string pPassword, eTLSRequirement pTLSRequirement = eTLSRequirement.required, bool pTryAuthenticateEvenIfPlainIsntAdvertised = false) { if (string.IsNullOrEmpty(pUserId)) { throw new ArgumentOutOfRangeException(nameof(pUserId)); } if (string.IsNullOrEmpty(pPassword)) { throw new ArgumentOutOfRangeException(nameof(pPassword)); } cLogin.TryConstruct(pUserId, pPassword, pTLSRequirement, out var lLogin); cSASLPlain.TryConstruct(pUserId, pPassword, pTLSRequirement, out var lPlain); if (lLogin == null && lPlain == null) { throw new ArgumentOutOfRangeException(); // argument_s_outofrange } var lCredentials = new cCredentials(pUserId, lLogin, pTryAuthenticateEvenIfPlainIsntAdvertised); if (lPlain != null) { lCredentials.mSASLs.Add(lPlain); } return(lCredentials); }
/// <summary> /// Initialises a new instance with the specified trace information and TLS requirement. Will throw if the trace information isn't valid. /// </summary> /// <param name="pTrace"></param> /// <param name="pTLSRequirement"></param> /// <inheritdoc cref="cSASLAnonymous" select="remarks"/> public cSASLAnonymous(string pTrace, eTLSRequirement pTLSRequirement) { if (!ZIsValid(pTrace)) { throw new ArgumentOutOfRangeException(nameof(pTrace)); } mTrace = pTrace; mTLSRequirement = pTLSRequirement; }
internal static bool TryConstruct(string pTrace, eTLSRequirement pTLSRequirement, out cSASLAnonymous rAnonymous) { if (ZIsValid(pTrace)) { rAnonymous = new cSASLAnonymous(pTrace, pTLSRequirement, true); return(true); } rAnonymous = null; return(false); }
/// <summary> /// Initialises a new instance with the specified authentication-id, password and TLS requirement. Will throw if the authentication-id or password are not valid. /// </summary> /// <param name="pAuthenticationId"></param> /// <param name="pPassword"></param> /// <param name="pTLSRequirement"></param> public cSASLPlain(string pAuthenticationId, string pPassword, eTLSRequirement pTLSRequirement) { if (string.IsNullOrEmpty(pAuthenticationId) || pAuthenticationId.IndexOf(cChar.NUL) != -1) { throw new ArgumentOutOfRangeException(nameof(pAuthenticationId)); } if (string.IsNullOrEmpty(pPassword) || pPassword.IndexOf(cChar.NUL) != -1) { throw new ArgumentOutOfRangeException(nameof(pPassword)); } mAuthenticationId = pAuthenticationId; mPassword = pPassword; mTLSRequirement = pTLSRequirement; }
internal static bool TryConstruct(string pUserId, string pPassword, eTLSRequirement pTLSRequirement, out cLogin rLogin) { if (string.IsNullOrEmpty(pUserId) || string.IsNullOrEmpty(pPassword)) { rLogin = null; return(false); } if (!cCommandPartFactory.TryAsASCIILiteral(pUserId, true, out _)) { rLogin = null; return(false); } if (!cCommandPartFactory.TryAsASCIILiteral(pPassword, true, out _)) { rLogin = null; return(false); } rLogin = new cLogin(pUserId, pPassword, pTLSRequirement, true); return(true); }
/// <summary> /// Returns a new set of anonymous credentials. /// </summary> /// <param name="pTrace">The trace information to be sent to the server.</param> /// <param name="pTLSRequirement">The TLS requirement for the credentials to be used.</param> /// <param name="pTryAuthenticateEvenIfAnonymousIsntAdvertised">Indicates whether the SASL ANONYMOUS mechanism should be tried even if not advertised.</param> /// <returns></returns> /// <remarks> /// The credentials returned may fall back to IMAP LOGIN if SASL ANONYMOUS isn't available. /// This method will throw if <paramref name="pTrace"/> can be used in neither <see cref="cLogin.Password"/> nor <see cref="cSASLAnonymous"/>. /// </remarks> public static cCredentials Anonymous(string pTrace, eTLSRequirement pTLSRequirement = eTLSRequirement.indifferent, bool pTryAuthenticateEvenIfAnonymousIsntAdvertised = false) { if (string.IsNullOrEmpty(pTrace)) { throw new ArgumentOutOfRangeException(nameof(pTrace)); } cLogin.TryConstruct("anonymous", pTrace, pTLSRequirement, out var lLogin); cSASLAnonymous.TryConstruct(pTrace, pTLSRequirement, out var lSASL); if (lLogin == null && lSASL == null) { throw new ArgumentOutOfRangeException(nameof(pTrace)); } var lCredentials = new cCredentials(eAccountType.anonymous, lLogin, pTryAuthenticateEvenIfAnonymousIsntAdvertised); if (lSASL != null) { lCredentials.mSASLs.Add(lSASL); } return(lCredentials); }
/// <summary> /// Initialises a new instance with the specified userid, password and TLS requirement. Will throw if the userid and password specified can't be used with IMAP LOGIN. /// </summary> /// <param name="pUserId"></param> /// <param name="pPassword"></param> /// <param name="pTLSRequirement">The TLS requirement for the userid and password to be used.</param> /// <inheritdoc cref="cLogin" select="remarks"/> public cLogin(string pUserId, string pPassword, eTLSRequirement pTLSRequirement) { if (string.IsNullOrEmpty(pUserId)) { throw new ArgumentOutOfRangeException(nameof(pUserId)); } if (string.IsNullOrEmpty(pPassword)) { throw new ArgumentOutOfRangeException(nameof(pPassword)); } if (!cCommandPartFactory.TryAsASCIILiteral(pUserId, true, out _)) { throw new ArgumentOutOfRangeException(nameof(pUserId)); } if (!cCommandPartFactory.TryAsASCIILiteral(pPassword, true, out _)) { throw new ArgumentOutOfRangeException(nameof(pPassword)); } UserId = pUserId; Password = pPassword; TLSRequirement = pTLSRequirement; }
internal static bool TryConstruct(string pAuthenticationId, string pPassword, eTLSRequirement pTLSRequirement, out cSASLPlain rPlain) { if (!string.IsNullOrEmpty(pAuthenticationId) && pAuthenticationId.IndexOf(cChar.NUL) == -1 && !string.IsNullOrEmpty(pPassword) && pPassword.IndexOf(cChar.NUL) == -1) { rPlain = new cSASLPlain(pAuthenticationId, pPassword, pTLSRequirement, true); return(true); } rPlain = null; return(false); }
private cSASLPlain(string pAuthenticationId, string pPassword, eTLSRequirement pTLSRequirement, bool pPrechecked) { mAuthenticationId = pAuthenticationId; mPassword = pPassword; mTLSRequirement = pTLSRequirement; }
private cSASLAnonymous(string pTrace, eTLSRequirement pTLSRequirement, bool pPrechecked) { mTrace = pTrace; mTLSRequirement = pTLSRequirement; }
private cLogin(string pUserId, string pPassword, eTLSRequirement pTLSRequirement, bool pValidated) { UserId = pUserId; Password = pPassword; TLSRequirement = pTLSRequirement; }