| 370 | } |
| 371 | |
| 372 | std::optional<std::string> CryptoModule::validatePrekey() { |
| 373 | static const uint64_t maxPrekeyPublishTime = 30 * 24 * 60 * 60; // 30 days |
| 374 | static const uint64_t maxOldPrekeyAge = 24 * 60 * 60; // 24 hours |
| 375 | std::optional<std::string> maybeNewPrekey; |
| 376 | |
| 377 | bool prekeyDoesntExist = this->prekeyDoesntExist(); |
| 378 | bool prekeySignatureValid = this->isPrekeySignatureValid(); |
| 379 | if (prekeyDoesntExist || !prekeySignatureValid) { |
| 380 | return this->generateAndGetPrekey(); |
| 381 | } |
| 382 | |
| 383 | bool shouldRotatePrekey = |
| 384 | this->prekeyExistsAndOlderThan(maxPrekeyPublishTime); |
| 385 | if (shouldRotatePrekey) { |
| 386 | maybeNewPrekey = this->generateAndGetPrekey(); |
| 387 | } |
| 388 | |
| 389 | bool shouldForgetPrekey = this->prekeyExistsAndOlderThan(maxOldPrekeyAge); |
| 390 | if (shouldForgetPrekey) { |
| 391 | this->forgetOldPrekey(); |
| 392 | } |
| 393 | |
| 394 | return maybeNewPrekey; |
| 395 | } |
| 396 | |
| 397 | } // namespace crypto |
| 398 | } // namespace comm |
no test coverage detected