2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
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.
11 #ifndef WEBRTC_LIBJINGLE_XMPP_SASLPLAINMECHANISM_H_
12 #define WEBRTC_LIBJINGLE_XMPP_SASLPLAINMECHANISM_H_
14 #include "webrtc/libjingle/xmpp/saslmechanism.h"
15 #include "webrtc/base/cryptstring.h"
19 class SaslPlainMechanism : public SaslMechanism {
22 SaslPlainMechanism(const buzz::Jid user_jid, const rtc::CryptString & password) :
23 user_jid_(user_jid), password_(password) {}
25 virtual std::string GetMechanismName() { return "PLAIN"; }
27 virtual XmlElement * StartSaslAuth() {
28 // send initial request
29 XmlElement * el = new XmlElement(QN_SASL_AUTH, true);
30 el->AddAttr(QN_MECHANISM, "PLAIN");
32 rtc::FormatCryptString credential;
33 credential.Append("\0", 1);
34 credential.Append(user_jid_.node());
35 credential.Append("\0", 1);
36 credential.Append(&password_);
37 el->AddText(Base64EncodeFromArray(credential.GetData(), credential.GetLength()));
43 rtc::CryptString password_;
48 #endif // WEBRTC_LIBJINGLE_XMPP_SASLPLAINMECHANISM_H_