IList<AuthenticationSecret> DetectAuthSecrets (byte[] buffer, int offset, int endIndex) { int index = offset; if (commandState == ImapAuthCommandState.Authenticate) { if (SkipText ("AUTHENTICATE ", buffer, ref index, endIndex)) commandState = ImapAuthCommandState.AuthMechanism; if (index >= endIndex || commandState == ImapAuthCommandState.Error) return EmptyAuthSecrets; } if (commandState == ImapAuthCommandState.AuthMechanism) { while (index < endIndex && buffer[index] != (byte) ' ' && buffer[index] != (byte) '\r') index++; if (index < endIndex) { if (buffer[index] == (byte) ' ') { commandState = ImapAuthCommandState.AuthToken; } else { commandState = ImapAuthCommandState.AuthNewLine; } index++; } if (index >= endIndex) return EmptyAuthSecrets; } if (commandState == ImapAuthCommandState.AuthNewLine) { if (buffer[index] == (byte) '\n') { commandState = ImapAuthCommandState.AuthToken; index++; } else { commandState = ImapAuthCommandState.Error; } if (index >= endIndex || commandState == ImapAuthCommandState.Error) return EmptyAuthSecrets; } int startIndex = index; while (index < endIndex && buffer[index] != (byte) '\r') index++; if (index < endIndex) commandState = ImapAuthCommandState.AuthNewLine; if (index == startIndex) return EmptyAuthSecrets; var secret = new AuthenticationSecret (startIndex, index - startIndex); return new AuthenticationSecret[] { secret }; }
public IList <AuthenticationSecret> DetectSecrets(byte[] buffer, int offset, int count) { if (!IsAuthenticating || state == SmtpAuthCommandState.Error || count == 0) { return(EmptyAuthSecrets); } int endIndex = offset + count; int index = offset; if (state == SmtpAuthCommandState.Auth) { if (SkipCommand("AUTH ", buffer, ref index, endIndex)) { state = SmtpAuthCommandState.AuthMechanism; } if (index >= endIndex || state == SmtpAuthCommandState.Error) { return(EmptyAuthSecrets); } } if (state == SmtpAuthCommandState.AuthMechanism) { while (index < endIndex && buffer[index] != (byte)' ' && buffer[index] != (byte)'\r') { index++; } if (index < endIndex) { if (buffer[index] == (byte)' ') { state = SmtpAuthCommandState.AuthToken; } else { state = SmtpAuthCommandState.AuthNewLine; } index++; } if (index >= endIndex) { return(EmptyAuthSecrets); } } if (state == SmtpAuthCommandState.AuthNewLine) { if (buffer[index] == (byte)'\n') { state = SmtpAuthCommandState.AuthToken; index++; } else { state = SmtpAuthCommandState.Error; } if (index >= endIndex || state == SmtpAuthCommandState.Error) { return(EmptyAuthSecrets); } } int startIndex = index; while (index < endIndex && buffer[index] != (byte)'\r') { index++; } if (index < endIndex) { state = SmtpAuthCommandState.AuthNewLine; } if (index == startIndex) { return(EmptyAuthSecrets); } var secret = new AuthenticationSecret(startIndex, index - startIndex); if (state == SmtpAuthCommandState.AuthNewLine) { index++; if (index < endIndex) { if (buffer[index] == (byte)'\n') { state = SmtpAuthCommandState.AuthToken; } else { state = SmtpAuthCommandState.Error; } } } return(new AuthenticationSecret[] { secret }); }