int len = MIN(tag_len, sizeof(task->task_pool->tag.uid) - 1);
memcpy(task->task_pool->tag.uid, tag, len);
task->task_pool->tag.uid[len] = '\0';
+ /* Keep UUID random portion in sync with the new log tag */
+ rspamd_uuid_v7_patch_uid(task->task_uuid, tag, tag_len);
}
}
return 0;
}
+void rspamd_uuid_v7_patch_uid(char uuid[37], const char *tag, gsize tag_len)
+{
+ uint8_t bytes[8];
+ char hex[16];
+
+ /* Hash the tag to get 8 bytes for UUID positions 8-15 */
+ uint64_t h = rspamd_cryptobox_fast_hash(tag, tag_len, 0x7569645f763700ULL);
+ memcpy(bytes, &h, sizeof(h));
+
+ /* Preserve variant bits: byte 8 must have top 2 bits = 10 */
+ bytes[0] = 0x80 | (bytes[0] & 0x3f);
+
+ /* Hex-encode and patch into UUID string:
+ * positions 19-22 = bytes 8-9, positions 24-35 = bytes 10-15 */
+ rspamd_encode_hex_buf(bytes, 8, hex, sizeof(hex));
+ memcpy(uuid + 19, hex, 4);
+ memcpy(uuid + 24, hex + 4, 12);
+}
+
int rspamd_shmem_mkstemp(char *pattern)
{
int fd = -1;
*/
int rspamd_uuid_v7(char uuid_out[37], char *opt_uid_buf, gsize uid_buflen, double timestamp);
+/**
+ * Patch UUID v7 random portion (bytes 8-15) to match a new log tag.
+ * Hashes the tag to derive bytes, preserves timestamp and version/variant bits.
+ * @param uuid UUID string to patch in place (36 chars + NUL)
+ * @param tag new log tag value
+ * @param tag_len length of tag
+ */
+void rspamd_uuid_v7_patch_uid(char uuid[37], const char *tag, gsize tag_len);
+
/**
* Returns
* @param pattern pattern to create (should end with some number of X symbols), modified by this function