ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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 41 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 43 of file peer_crypto.cpp.

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

References binding_copy_input(), ERROR_INVALID_PARAM, peer_crypto_create(), 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 83 of file peer_crypto.cpp.

83 {
84 return peer_crypto_quic_begin(peer_.get());
85 }
asciichat_error_t peer_crypto_quic_begin(browser_peer_crypto_t *peer)

References peer_crypto_quic_begin().

Referenced by EMSCRIPTEN_BINDINGS().

◆ error()

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

Definition at line 71 of file peer_crypto.cpp.

71 {
72 return peer_crypto_error();
73 }
const char * peer_crypto_error(void)
Definition peer_crypto.c:32

References peer_crypto_error().

Referenced by EMSCRIPTEN_BINDINGS().

◆ initQuic()

int PeerCryptoBinding::initQuic ( )
inline

Definition at line 86 of file peer_crypto.cpp.

86 {
88 }
crypto_context_t * peer_security_context(browser_peer_crypto_t *peer)
asciichat_error_t browser_security_init(crypto_context_t *ctx)

References browser_security_init(), and peer_security_context().

Referenced by EMSCRIPTEN_BINDINGS().

◆ operator=()

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

References PeerCryptoBinding().

◆ quicEpoch()

double PeerCryptoBinding::quicEpoch ( )
inline

Definition at line 92 of file peer_crypto.cpp.

92 {
94 }
double browser_security_epoch(crypto_context_t *ctx)

References browser_security_epoch(), and peer_security_context().

Referenced by EMSCRIPTEN_BINDINGS().

◆ quicPacket()

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

Definition at line 112 of file peer_crypto.cpp.

112 {
113 return network_quic_packet(peer_security_context(peer_.get()), seal, flow, delivery, packet);
114 }
QuicPacketResult network_quic_packet(crypto_context_t *context, bool seal, unsigned flow, unsigned delivery, PeerBytes packet)

References network_quic_packet(), and peer_security_context().

Referenced by EMSCRIPTEN_BINDINGS().

◆ ready()

bool PeerCryptoBinding::ready ( ) const
inline

Definition at line 68 of file peer_crypto.cpp.

68 {
69 return peer_ && peer_crypto_ready(peer_.get());
70 }
bool peer_crypto_ready(browser_peer_crypto_t *peer)

References peer_crypto_ready().

Referenced by EMSCRIPTEN_BINDINGS().

◆ receive()

int PeerCryptoBinding::receive ( PeerBytes packet)
inline

Definition at line 77 of file peer_crypto.cpp.

77 {
78 return input(packet, true);
79 }

Referenced by EMSCRIPTEN_BINDINGS().

◆ received()

NullablePeerBytes PeerCryptoBinding::received ( )
inline

Definition at line 104 of file peer_crypto.cpp.

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

References binding_copy_output(), peer_crypto_received_data(), and peer_crypto_received_size().

Referenced by EMSCRIPTEN_BINDINGS().

◆ send()

int PeerCryptoBinding::send ( PeerBytes packet)
inline

Definition at line 74 of file peer_crypto.cpp.

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

Referenced by EMSCRIPTEN_BINDINGS().

◆ takeOutput()

NullablePeerBytes PeerCryptoBinding::takeOutput ( )
inline

Definition at line 96 of file peer_crypto.cpp.

96 {
97 const void *data = peer_crypto_output_data(peer_.get());
98 if (!data)
99 return NullablePeerBytes(emscripten::val::null());
100 emscripten::val output = binding_copy_output(data, peer_crypto_output_size(peer_.get()));
101 peer_crypto_output_pop(peer_.get());
102 return NullablePeerBytes(output);
103 }
void peer_crypto_output_pop(browser_peer_crypto_t *peer)
Definition peer_crypto.c:84
size_t peer_crypto_output_size(browser_peer_crypto_t *peer)
const void * peer_crypto_output_data(browser_peer_crypto_t *peer)

References binding_copy_output(), peer_crypto_output_data(), peer_crypto_output_pop(), and peer_crypto_output_size().

Referenced by EMSCRIPTEN_BINDINGS().

◆ takeQuicOutput()

QuicControlResult PeerCryptoBinding::takeQuicOutput ( )
inline

Definition at line 109 of file peer_crypto.cpp.

109 {
110 return network_quic_output(peer_security_context(peer_.get()));
111 }
QuicControlResult network_quic_output(crypto_context_t *context)

References network_quic_output(), and peer_security_context().

Referenced by EMSCRIPTEN_BINDINGS().

◆ tick()

int PeerCryptoBinding::tick ( )
inline

Definition at line 80 of file peer_crypto.cpp.

80 {
81 return peer_crypto_tick(peer_.get());
82 }
asciichat_error_t peer_crypto_tick(browser_peer_crypto_t *peer)

References peer_crypto_tick().

Referenced by EMSCRIPTEN_BINDINGS().

◆ tickQuic()

int PeerCryptoBinding::tickQuic ( )
inline

Definition at line 89 of file peer_crypto.cpp.

89 {
91 }
asciichat_error_t browser_security_tick(crypto_context_t *ctx)

References browser_security_tick(), and peer_security_context().

Referenced by EMSCRIPTEN_BINDINGS().

◆ valid()

bool PeerCryptoBinding::valid ( ) const
inline

Definition at line 65 of file peer_crypto.cpp.

65 {
66 return static_cast<bool>(peer_);
67 }

Referenced by EMSCRIPTEN_BINDINGS().


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