* @brief Verifies a certificate and, on success, installs the token and persists it. */
| 342 | * @brief Verifies a certificate and, on success, installs the token and persists it. |
| 343 | */ |
| 344 | bool Licensing::OfflineLicense::applyCertificate(const QByteArray& framedCert, bool persist) |
| 345 | { |
| 346 | const qint64 nowSecs = MonotonicClock::now().toSecsSinceEpoch(); |
| 347 | |
| 348 | CertificateFields fields; |
| 349 | const auto status = |
| 350 | verifyCertificate(framedCert, kOfflinePublicKey, machineId(), nowSecs, fields); |
| 351 | if (status != CertStatus::Valid) { |
| 352 | m_lastError = certStatusReason(status); |
| 353 | if (persist) |
| 354 | showOfflineError(m_lastError); |
| 355 | |
| 356 | return false; |
| 357 | } |
| 358 | |
| 359 | m_activated = true; |
| 360 | m_lastError = QString(); |
| 361 | m_variantName = fields.variant; |
| 362 | m_expiresAt = QDateTime::fromSecsSinceEpoch(fields.expiresAt); |
| 363 | |
| 364 | if (!LemonSqueezy::instance().isOnlineActivated()) { |
| 365 | const int days = qMax(0, static_cast<int>((fields.expiresAt - nowSecs) / 86400)); |
| 366 | installOfflineToken(fields, days); |
| 367 | } |
| 368 | |
| 369 | if (persist) |
| 370 | writeSettings(framedCert); |
| 371 | |
| 372 | Q_EMIT activatedChanged(); |
| 373 | return true; |
| 374 | } |
nothing calls this directly
no test coverage detected