Files
roro9stack/lib/ota/src/version_compare.h
T
twislaandClaude Opus 5.5 326e864264 OTA step 1: Update File format and streaming parser (host-tested)
lib/ota: a 160-byte header (magic, format, image size and SHA-256,
version, ECDSA signature over the first 80 bytes) then the image.
UpdateParser checks the header and signature before writing anything,
hashes the image as it streams into an UpdateSink, and only finishes
the sink when the hash matches. Downgrades are flagged, not refused.
Includes a dependency-free SHA-256 and semver comparison.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-03 21:30:13 +02:00

34 lines
1.0 KiB
C++

#pragma once
#include <cstdlib>
#include <string>
namespace roro {
// True if `a` is an older release than `b`, comparing "vMAJOR.MINOR.PATCH" and ignoring any
// git-describe suffix ("-3-gabc1234-dirty"). Anything that doesn't parse is never called older.
inline bool parseVersion(const std::string& s, int out[3]) {
size_t pos = s.size() > 0 && s[0] == 'v' ? 1 : 0;
for (int i = 0; i < 3; i++) {
if (pos >= s.size() || s[pos] < '0' || s[pos] > '9') return false;
char* end;
out[i] = static_cast<int>(std::strtol(s.c_str() + pos, &end, 10));
pos = end - s.c_str();
if (i < 2) {
if (pos >= s.size() || s[pos] != '.') return false;
pos++;
}
}
return true;
}
inline bool versionOlder(const std::string& a, const std::string& b) {
int x[3], y[3];
if (!parseVersion(a, x) || !parseVersion(b, y)) return false;
for (int i = 0; i < 3; i++)
if (x[i] != y[i]) return x[i] < y[i];
return false;
}
} // namespace roro