MCPcopy Create free account
hub / github.com/diasurgical/devilution / decrypt

Method decrypt

SourceX/dvlnet/packet.cpp:145–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145void packet_in::decrypt()
146{
147 if (!have_encrypted)
148 ABORT();
149 if (have_decrypted)
150 return;
151#ifndef NONET
152 if (!disable_encryption) {
153 if (encrypted_buffer.size() < crypto_secretbox_NONCEBYTES
154 + crypto_secretbox_MACBYTES
155 + sizeof(packet_type) + 2 * sizeof(plr_t))
156 throw packet_exception();
157 auto pktlen = (encrypted_buffer.size()
158 - crypto_secretbox_NONCEBYTES
159 - crypto_secretbox_MACBYTES);
160 decrypted_buffer.resize(pktlen);
161 if (crypto_secretbox_open_easy(decrypted_buffer.data(),
162 encrypted_buffer.data()
163 + crypto_secretbox_NONCEBYTES,
164 encrypted_buffer.size()
165 - crypto_secretbox_NONCEBYTES,
166 encrypted_buffer.data(),
167 key.data()))
168 throw packet_exception();
169 } else
170#endif
171 {
172 if (encrypted_buffer.size() < sizeof(packet_type) + 2 * sizeof(plr_t))
173 throw packet_exception();
174 decrypted_buffer = encrypted_buffer;
175 }
176
177 process_data();
178
179 have_decrypted = true;
180}
181
182void packet_out::encrypt()
183{

Callers 1

make_packetMethod · 0.80

Calls 4

packet_exceptionClass · 0.85
sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected