mirror of
https://github.com/esphome/esphome.git
synced 2025-07-29 06:36:45 +00:00
[api] Reduce code duplication in send_noise_encryption_set_key_response (#9918)
This commit is contained in:
parent
84ed1bcf34
commit
7f0c66f835
@ -1538,19 +1538,18 @@ void APIConnection::execute_service(const ExecuteServiceRequest &msg) {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_API_NOISE
|
#ifdef USE_API_NOISE
|
||||||
bool APIConnection::send_noise_encryption_set_key_response(const NoiseEncryptionSetKeyRequest &msg) {
|
bool APIConnection::send_noise_encryption_set_key_response(const NoiseEncryptionSetKeyRequest &msg) {
|
||||||
psk_t psk{};
|
|
||||||
NoiseEncryptionSetKeyResponse resp;
|
NoiseEncryptionSetKeyResponse resp;
|
||||||
|
resp.success = false;
|
||||||
|
|
||||||
|
psk_t psk{};
|
||||||
if (base64_decode(msg.key, psk.data(), msg.key.size()) != psk.size()) {
|
if (base64_decode(msg.key, psk.data(), msg.key.size()) != psk.size()) {
|
||||||
ESP_LOGW(TAG, "Invalid encryption key length");
|
ESP_LOGW(TAG, "Invalid encryption key length");
|
||||||
resp.success = false;
|
} else if (!this->parent_->save_noise_psk(psk, true)) {
|
||||||
return this->send_message(resp, NoiseEncryptionSetKeyResponse::MESSAGE_TYPE);
|
|
||||||
}
|
|
||||||
if (!this->parent_->save_noise_psk(psk, true)) {
|
|
||||||
ESP_LOGW(TAG, "Failed to save encryption key");
|
ESP_LOGW(TAG, "Failed to save encryption key");
|
||||||
resp.success = false;
|
} else {
|
||||||
return this->send_message(resp, NoiseEncryptionSetKeyResponse::MESSAGE_TYPE);
|
resp.success = true;
|
||||||
}
|
}
|
||||||
resp.success = true;
|
|
||||||
return this->send_message(resp, NoiseEncryptionSetKeyResponse::MESSAGE_TYPE);
|
return this->send_message(resp, NoiseEncryptionSetKeyResponse::MESSAGE_TYPE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user