* @brief Encrypts and writes the given plaintext key to QSettings. */
| 97 | * @brief Encrypts and writes the given plaintext key to QSettings. |
| 98 | */ |
| 99 | void AI::KeyVault::setKey(ProviderId provider, const QString& plaintext) |
| 100 | { |
| 101 | auto trimmed = plaintext.trimmed(); |
| 102 | ZeroOnDestroy scrub(trimmed); |
| 103 | |
| 104 | if (trimmed.isEmpty()) { |
| 105 | clearKey(provider); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | const auto cipher = m_simpleCrypt.encryptToString(trimmed); |
| 110 | m_settings.beginGroup(QStringLiteral("ai/keys")); |
| 111 | m_settings.setValue(settingsKey(provider), cipher); |
| 112 | m_settings.endGroup(); |
| 113 | |
| 114 | qCDebug(serialStudioAI) << "Key set for" << settingsKey(provider); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @brief Removes the stored key for the given provider. |
no test coverage detected