~singpolyma/biboumi

ref: d81c3ad5ac2c12130d90044b7597bf962a7cfe9e biboumi/louloulibs/xmpp/auth.cpp -rw-r--r-- 562 bytes
d81c3ad5 — louiz’ Fix the order of from and to address in muc traffic info reply 6 years ago
                                                                                
021f025c louiz’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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();
}