diff options
Diffstat (limited to 'Swiften/Serializer')
4 files changed, 14 insertions, 12 deletions
diff --git a/Swiften/Serializer/AuthRequestSerializer.cpp b/Swiften/Serializer/AuthRequestSerializer.cpp index 415a0ff..33bdd77 100644 --- a/Swiften/Serializer/AuthRequestSerializer.cpp +++ b/Swiften/Serializer/AuthRequestSerializer.cpp @@ -9,6 +9,7 @@ #include <Swiften/Elements/AuthRequest.h> #include <Swiften/StringCodecs/Base64.h> #include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/SafeString.h> namespace Swift { @@ -17,17 +18,17 @@ AuthRequestSerializer::AuthRequestSerializer() { std::string AuthRequestSerializer::serialize(boost::shared_ptr<Element> element) const { boost::shared_ptr<AuthRequest> authRequest(boost::dynamic_pointer_cast<AuthRequest>(element)); - std::string value; - boost::optional<std::vector<unsigned char> > message = authRequest->getMessage(); + SafeString value; + boost::optional<SafeByteArray> message = authRequest->getMessage(); if (message) { if ((*message).empty()) { value = "="; } else { - value = Base64::encode(ByteArray(*message)); + value = Base64::encode(*message); } } - return "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"" + authRequest->getMechanism() + "\">" + value + "</auth>"; + return "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"" + authRequest->getMechanism() + "\">" + value.toString() + "</auth>"; } } diff --git a/Swiften/Serializer/AuthResponseSerializer.cpp b/Swiften/Serializer/AuthResponseSerializer.cpp index 0d1872b..cfdcc99 100644 --- a/Swiften/Serializer/AuthResponseSerializer.cpp +++ b/Swiften/Serializer/AuthResponseSerializer.cpp @@ -9,6 +9,7 @@ #include <Swiften/Elements/AuthResponse.h> #include <Swiften/StringCodecs/Base64.h> #include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/SafeString.h> namespace Swift { @@ -17,17 +18,17 @@ AuthResponseSerializer::AuthResponseSerializer() { std::string AuthResponseSerializer::serialize(boost::shared_ptr<Element> element) const { boost::shared_ptr<AuthResponse> authResponse(boost::dynamic_pointer_cast<AuthResponse>(element)); - std::string value; - boost::optional<std::vector<unsigned char> > message = authResponse->getValue(); + SafeString value; + boost::optional<SafeByteArray> message = authResponse->getValue(); if (message) { if ((*message).empty()) { value = "="; } else { - value = Base64::encode(ByteArray(*message)); + value = Base64::encode(*message); } } - return "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value + "</response>"; + return "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value.toString() + "</response>"; } } diff --git a/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp index 8270139..d5c0a09 100644 --- a/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp +++ b/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp @@ -24,7 +24,7 @@ class AuthRequestSerializerTest : public CppUnit::TestFixture { void testSerialize() { AuthRequestSerializer testling; boost::shared_ptr<AuthRequest> authRequest(new AuthRequest("PLAIN")); - authRequest->setMessage(createByteArray("foo")); + authRequest->setMessage(createSafeByteArray("foo")); CPPUNIT_ASSERT_EQUAL(std::string( "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">" @@ -44,7 +44,7 @@ class AuthRequestSerializerTest : public CppUnit::TestFixture { void testSerialize_EmptyMessage() { AuthRequestSerializer testling; boost::shared_ptr<AuthRequest> authRequest(new AuthRequest("PLAIN")); - authRequest->setMessage(std::vector<unsigned char>()); + authRequest->setMessage(SafeByteArray()); CPPUNIT_ASSERT_EQUAL(std::string( "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">" diff --git a/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp index e790cc3..8887b27 100644 --- a/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp +++ b/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp @@ -24,7 +24,7 @@ class AuthResponseSerializerTest : public CppUnit::TestFixture { void testSerialize() { AuthResponseSerializer testling; boost::shared_ptr<AuthResponse> authResponse(new AuthResponse()); - authResponse->setValue(createByteArray("foo")); + authResponse->setValue(createSafeByteArray("foo")); CPPUNIT_ASSERT_EQUAL(std::string( "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" @@ -44,7 +44,7 @@ class AuthResponseSerializerTest : public CppUnit::TestFixture { void testSerialize_EmptyMessage() { AuthResponseSerializer testling; boost::shared_ptr<AuthResponse> authResponse(new AuthResponse()); - authResponse->setValue(std::vector<unsigned char>()); + authResponse->setValue(SafeByteArray()); CPPUNIT_ASSERT_EQUAL(std::string( "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" |