ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
PeerCryptoBinding Class Reference

Public Member Functions

 PeerCryptoBinding (bool server, int encryption, PeerBytes password, PeerBytes identity, PeerBytes expected)
 PeerCryptoBinding (const PeerCryptoBinding &)=delete
PeerCryptoBinding & operator= (const PeerCryptoBinding &)=delete
bool valid () const
bool ready () const
std::string error () const
int send (PeerBytes packet)
int receive (PeerBytes packet)
int tick ()
int beginQuic ()
int initQuic ()
int tickQuic ()
double quicEpoch ()
NullablePeerBytes takeOutput ()
NullablePeerBytes received ()
QuicControlResult takeQuicOutput ()
QuicPacketResult quicPacket (bool seal, unsigned flow, unsigned delivery, PeerBytes packet)

Detailed Description

Definition at line 39 of file peer_crypto.cpp.

Constructor & Destructor Documentation

◆ PeerCryptoBinding() [1/2]

PeerCryptoBinding::PeerCryptoBinding ( bool server,
int encryption,
PeerBytes password,
PeerBytes identity,
PeerBytes expected )
inline

Definition at line 41 of file peer_crypto.cpp.

41 {
42 auto pass = binding_copy_input(password);
43 auto secret = binding_copy_input(identity);
44 auto key = binding_copy_input(expected);
45 if ((!secret.empty() && secret.size() != 64) || (!key.empty() && key.size() != 32)) {
46 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid peer identity or verification key length");
47 } else {
48 pass.push_back(0);
49 peer_.reset(
50 peer_crypto_create(server, encryption, pass.size() > 1 ? reinterpret_cast<char *>(pass.data()) : nullptr, secret.empty() ? nullptr : secret.data(), key.empty() ? nullptr : key.data()));
51 }
52 if (!pass.empty())
53 sodium_memzero(pass.data(), pass.size());
54 if (!secret.empty())
55 sodium_memzero(secret.data(), secret.size());
56 if (!key.empty())
57 sodium_memzero(key.data(), key.size());
58 }
#define SET_ERRNO(code,...)
std::vector< uint8_t > binding_copy_input(emscripten::val bytes)
Definition byte_arrays.h:6
@ ERROR_INVALID_PARAM

References binding_copy_input(), ERROR_INVALID_PARAM, and SET_ERRNO.

Referenced by operator=(), and PeerCryptoBinding().

◆ PeerCryptoBinding() [2/2]

PeerCryptoBinding::PeerCryptoBinding ( const PeerCryptoBinding & )
delete

References PeerCryptoBinding().

Member Function Documentation

◆ beginQuic()

int PeerCryptoBinding::beginQuic ( )
inline

Definition at line 80 of file peer_crypto.cpp.

80 {
81 return peer_crypto_quic_begin(peer_.get());
82 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ error()

std::string PeerCryptoBinding::error ( ) const
inline

Definition at line 68 of file peer_crypto.cpp.

68 {
69 return peer_crypto_error();
70 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ initQuic()

int PeerCryptoBinding::initQuic ( )
inline

Definition at line 83 of file peer_crypto.cpp.

83 {
84 return browser_security_init(peer_security_context(peer_.get()));
85 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ operator=()

PeerCryptoBinding & PeerCryptoBinding::operator= ( const PeerCryptoBinding & )
delete

References PeerCryptoBinding().

◆ quicEpoch()

double PeerCryptoBinding::quicEpoch ( )
inline

Definition at line 89 of file peer_crypto.cpp.

89 {
90 return browser_security_epoch(peer_security_context(peer_.get()));
91 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ quicPacket()

QuicPacketResult PeerCryptoBinding::quicPacket ( bool seal,
unsigned flow,
unsigned delivery,
PeerBytes packet )
inline

Definition at line 109 of file peer_crypto.cpp.

109 {
110 return network_quic_packet(peer_security_context(peer_.get()), seal, flow, delivery, packet);
111 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ ready()

bool PeerCryptoBinding::ready ( ) const
inline

Definition at line 65 of file peer_crypto.cpp.

65 {
66 return peer_ && peer_crypto_ready(peer_.get());
67 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ receive()

int PeerCryptoBinding::receive ( PeerBytes packet)
inline

Definition at line 74 of file peer_crypto.cpp.

74 {
75 return input(packet, true);
76 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ received()

NullablePeerBytes PeerCryptoBinding::received ( )
inline

Definition at line 101 of file peer_crypto.cpp.

101 {
102 const void *data = peer_crypto_received_data(peer_.get());
103 const size_t length = peer_crypto_received_size(peer_.get());
104 return NullablePeerBytes(data && length ? binding_copy_output(data, length) : emscripten::val::null());
105 }
emscripten::val binding_copy_output(const void *data, size_t length)
Definition byte_arrays.h:18

References binding_copy_output().

Referenced by EMSCRIPTEN_BINDINGS().

◆ send()

int PeerCryptoBinding::send ( PeerBytes packet)
inline

Definition at line 71 of file peer_crypto.cpp.

71 {
72 return input(packet, false);
73 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ takeOutput()

NullablePeerBytes PeerCryptoBinding::takeOutput ( )
inline

Definition at line 93 of file peer_crypto.cpp.

93 {
94 const void *data = peer_crypto_output_data(peer_.get());
95 if (!data)
96 return NullablePeerBytes(emscripten::val::null());
97 emscripten::val output = binding_copy_output(data, peer_crypto_output_size(peer_.get()));
98 peer_crypto_output_pop(peer_.get());
99 return NullablePeerBytes(output);
100 }

References binding_copy_output().

Referenced by EMSCRIPTEN_BINDINGS().

◆ takeQuicOutput()

QuicControlResult PeerCryptoBinding::takeQuicOutput ( )
inline

Definition at line 106 of file peer_crypto.cpp.

106 {
107 return network_quic_output(peer_security_context(peer_.get()));
108 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ tick()

int PeerCryptoBinding::tick ( )
inline

Definition at line 77 of file peer_crypto.cpp.

77 {
78 return peer_crypto_tick(peer_.get());
79 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ tickQuic()

int PeerCryptoBinding::tickQuic ( )
inline

Definition at line 86 of file peer_crypto.cpp.

86 {
87 return browser_security_tick(peer_security_context(peer_.get()));
88 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ valid()

bool PeerCryptoBinding::valid ( ) const
inline

Definition at line 62 of file peer_crypto.cpp.

62 {
63 return static_cast<bool>(peer_);
64 }

Referenced by EMSCRIPTEN_BINDINGS().


The documentation for this class was generated from the following file: