saslmechanism.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2004 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef THIRD_PARTY_LIBJINGLE_XMPP_XMPP_SASLMECHANISM_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMPP_SASLMECHANISM_H_
  12. #include <string>
  13. namespace jingle_xmpp {
  14. class XmlElement;
  15. // Defines a mechnanism to do SASL authentication.
  16. // Subclass instances should have a self-contained way to present
  17. // credentials.
  18. class SaslMechanism {
  19. public:
  20. // Intended to be subclassed
  21. virtual ~SaslMechanism() {}
  22. // Should return the name of the SASL mechanism, e.g., "PLAIN"
  23. virtual std::string GetMechanismName() = 0;
  24. // Should generate the initial "auth" request. Default is just <auth/>.
  25. virtual XmlElement * StartSaslAuth();
  26. // Should respond to a SASL "<challenge>" request. Default is
  27. // to abort (for mechanisms that do not do challenge-response)
  28. virtual XmlElement * HandleSaslChallenge(const XmlElement * challenge);
  29. // Notification of a SASL "<success>". Sometimes information
  30. // is passed on success.
  31. virtual void HandleSaslSuccess(const XmlElement * success);
  32. // Notification of a SASL "<failure>". Sometimes information
  33. // for the user is passed on failure.
  34. virtual void HandleSaslFailure(const XmlElement * failure);
  35. protected:
  36. static std::string Base64Encode(const std::string & plain);
  37. static std::string Base64Decode(const std::string & encoded);
  38. static std::string Base64EncodeFromArray(const char * plain, size_t length);
  39. };
  40. }
  41. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMPP_SASLMECHANISM_H_