esp-signed-updater-mqtt/include/signedUpdatesHelper.h
2020-05-06 21:16:19 +02:00

29 lines
773 B
C

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#ifdef PUBLIC_SIGN_KEY
const char pubkey[] PROGMEM = PUBLIC_SIGN_KEY;
BearSSL::PublicKey *signPubKey = nullptr;
BearSSL::HashSHA256 *hash;
BearSSL::SigningVerifier *sign;
void signedUpdatesHelperInit() {
signPubKey = new BearSSL::PublicKey(pubkey);
hash = new BearSSL::HashSHA256();
sign = new BearSSL::SigningVerifier(signPubKey);
Update.installSignature(hash, sign);
}
String signedUpdatesHelperRun(WiFiClient& wifi, const String& url, const String& currentVersion = "") {
t_httpUpdate_return ret = ESPhttpUpdate.update(wifi, url, currentVersion);
if (ret == HTTP_UPDATE_FAILED)
return ESPhttpUpdate.getLastErrorString();
return String();
}
#endif