- hmac_sign now takes method+path instead of device_id; builds message as method\npath\ntimestamp\nhex(sha256(body)) per server verify_device_hmac - reporter: header renamed X-HMAC-Signature → X-Signature; passes "POST"+path - test vector regenerated against new message format; timestamp-diff test updated - .size() → .length() throughout (Arduino String has no size()) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
21 lines
618 B
C++
21 lines
618 B
C++
// firmware/src/hmac.h
|
|
#pragma once
|
|
#include <stdint.h>
|
|
|
|
#ifdef NATIVE_TEST
|
|
#include <string>
|
|
using HString = std::string;
|
|
#else
|
|
#include <Arduino.h>
|
|
using HString = String;
|
|
#endif
|
|
|
|
// Returns lowercase hex-encoded HMAC-SHA256 signature.
|
|
// Message signed: method + "\n" + path + "\n" + timestamp_str + "\n" + hex(sha256(body))
|
|
// Matches server verify_device_hmac format: POST\n{path}\n{timestamp}\n{sha256(body)}
|
|
HString hmac_sign(const HString& secret_hex,
|
|
const HString& method,
|
|
const HString& path,
|
|
uint32_t timestamp,
|
|
const HString& body);
|