-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSRS.cpp
37 lines (29 loc) · 837 Bytes
/
SRS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "SRS.hpp"
#include <srs2.h>
#include <glog/logging.h>
#include "SRS.ipp"
SRS::SRS()
: srs_(srs_new())
{
CHECK_NOTNULL(srs_);
add_secret(srs_secret);
}
SRS::~SRS() { srs_free(srs_); }
std::string SRS::forward(char const* sender, char const* alias) const
{
if (!*sender)
return sender;
char buf[1024]; // will be of size at most strlen(sender) + strlen(alias) + 64
CHECK_EQ(srs_forward(srs_, buf, sizeof(buf), sender, alias), SRS_SUCCESS);
return std::string(buf);
}
std::string SRS::reverse(char const* sender) const
{
if (!*sender)
return sender;
char buf[1024]; // no longer than sender
CHECK_EQ(srs_reverse(srs_, buf, sizeof(buf), sender), SRS_SUCCESS)
<< "sender == " << sender;
return std::string(buf);
}
void SRS::add_secret(char const* secret) { srs_add_secret(srs_, secret); }