std::string uuid() { boost::uuids::uuid id = boost::uuids::random_generator()(); const std::string r = boost::lexical_cast<std::string>(id); ENSURE_FALSE(r.empty()); return r; }
dh_secret::dh_secret() { u::mutex_scoped_lock l(BOTAN_MUTEX); init_rng(); CHECK(RNG); b::DL_Group sd{SHARED_DOMAIN}; _pkey = std::make_shared<b::DH_PrivateKey>(*RNG, sd); auto p = _pkey->public_value(); _pub_value = u::bytes{std::begin(p), std::end(p)}; ENSURE(_pkey); ENSURE_FALSE(_pub_value.empty()); }
public_key& public_key::operator=(const public_key& o) { if(&o == this) return *this; u::mutex_scoped_lock l(BOTAN_MUTEX); _ks = o._ks; b::DataSource_Memory ds{reinterpret_cast<const b::byte*>(&_ks[0]), _ks.size()}; _k.reset(b::X509::load_key(ds)); ENSURE(_k); ENSURE_NOT_EQUAL(_k, o._k); ENSURE_FALSE(_ks.empty()); ENSURE_EQUAL(_ks, o._ks); return *this; }
container split( const std::string& s, const std::string& delimiters) { container result; boost::char_separator<char> d{delimiters.c_str()}; boost::tokenizer<boost::char_separator<char>> tokens{s, d}; for(auto t : tokens) { trim(t); if(!t.empty()) result.insert(result.end(), t); } ENSURE_FALSE(result.empty()); return result; }
service::service( message::mailbox_ptr mail, message::mailbox_ptr event) : _done{false}, _mail{mail}, _event{event} { REQUIRE(mail); _address = mail->address(); ENSURE(_mail); ENSURE_FALSE(_address.empty()); ENSURE(_thread == nullptr); }
master_post_office::master_post_office( const std::string& in_host, n::port_type in_port, sc::encrypted_channels_ptr sl) : _in_host(in_host), _in_port{in_port}, _connections{POOL_SIZE, in_port, false}, _encrypted_channels{sl} { _address = n::make_udp_address(_in_host,_in_port); _in_thread.reset(new std::thread{in_thread, this}); _out_thread.reset(new std::thread{out_thread, this}); ENSURE(_in_thread); ENSURE(_out_thread); ENSURE_FALSE(_address.empty()); }
master_post_office::master_post_office( const std::string& in_host, n::port_type in_port, sc::session_library_ptr sl) : _in_host{in_host}, _in_port{in_port}, _connections{POOL_SIZE, in_port}, _session_library{sl} { _address = n::make_udp_address(_in_host,_in_port); _in_thread.reset(new std::thread{in_thread, this}); _out_thread.reset(new std::thread{out_thread, this}); ENSURE(_in_thread); ENSURE(_out_thread); ENSURE_FALSE(_address.empty()); }
std::string user_tooltip( us::user_info_ptr c, user_state s, const us::contact_version& version) { REQUIRE(c); std::string text; switch(s) { case REMOVED: text = "not here"; break; case OFFLINE: text = "offline"; break; case ONLINE: { text = "online "; if(version.client < u::CLIENT_VERSION) text = "older client "; else if(version.client > u::CLIENT_VERSION) text = "newer client "; if(version.protocol < u::PROTOCOL_VERSION) text = "older protocol "; if(version.protocol > u::PROTOCOL_VERSION) text = "newer protocol "; std::stringstream ss; ss << "(" << version.protocol << "." << version.client << ")"; text += ss.str(); } break; case IDLE: text = "away"; break; default: CHECK(false && "missed case"); }; ENSURE_FALSE(text.empty()); return text; }
const std::string& script_app::type() const { ENSURE_FALSE(SCRIPT_APP.empty()); return SCRIPT_APP; }
const std::string& script_app::id() const { ENSURE_FALSE(_id.empty()); return _id; }
const std::string& chat_app::type() const { ENSURE_FALSE(CHAT.empty()); return CHAT; }
const std::string& public_key::key() const { INVARIANT(_k); ENSURE_FALSE(_ks.empty()); return _ks; }
const std::string& private_key::public_key() const { INVARIANT(_k); ENSURE_FALSE(_public_key.empty()); return _public_key; }