MCPcopy Create free account
hub / github.com/CommE2E/comm / validatePrekey

Method validatePrekey

native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp:372–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370}
371
372std::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

Callers 2

validateAndGetPrekeysMethod · 0.80

Calls 5

prekeyDoesntExistMethod · 0.95
generateAndGetPrekeyMethod · 0.95
forgetOldPrekeyMethod · 0.95

Tested by

no test coverage detected