summaryrefslogtreecommitdiff
path: root/louloulibs/xmpp/auth.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'louloulibs/xmpp/auth.cpp')
-rw-r--r--louloulibs/xmpp/auth.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/louloulibs/xmpp/auth.cpp b/louloulibs/xmpp/auth.cpp
new file mode 100644
index 0000000..c20f95d
--- /dev/null
+++ b/louloulibs/xmpp/auth.cpp
@@ -0,0 +1,21 @@
+#include <xmpp/auth.hpp>
+
+#include <utils/sha1.hpp>
+
+#include <iomanip>
+#include <sstream>
+
+std::string get_handshake_digest(const std::string& stream_id, const std::string& secret)
+{
+ sha1nfo sha1;
+ sha1_init(&sha1);
+ sha1_write(&sha1, stream_id.data(), stream_id.size());
+ sha1_write(&sha1, secret.data(), secret.size());
+ const uint8_t* result = sha1_result(&sha1);
+
+ std::ostringstream digest;
+ for (int i = 0; i < HASH_LENGTH; i++)
+ digest << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>(result[i]);
+
+ return digest.str();
+}