| 143 | } |
| 144 | |
| 145 | void 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 | |
| 182 | void packet_out::encrypt() |
| 183 | { |
no test coverage detected