lab4: исправления по ревью

This commit is contained in:
Vladislav Kunetskiy
2026-10-21 23:25:11 +03:00
parent 3389c6c900
commit e9f0fde6f2
32 changed files with 451 additions and 131 deletions
+8 -9
View File
@@ -9,7 +9,6 @@ import (
"fmt"
"io"
"net/http"
"slices"
"time"
"github.com/google/uuid"
@@ -271,15 +270,15 @@ func (h *Handler) CreateMessage(
}, nil
}
// messageFingerprint canonicalises the create-message payload so that the key
// order of the client JSON cannot change the fingerprint, while a different
// payload with the same Idempotency-Key can (contract 1.3.0).
// messageFingerprint canonicalises the create-message payload so that JSON key
// order cannot change the fingerprint, while a different payload (including a
// different attachment order) with the same Idempotency-Key can. Absent
// attachment_ids and [] are equivalent, as required by the contract.
func messageFingerprint(req *oas.CreateMessage) ([sha256.Size]byte, error) {
ids := make([]uuid.UUID, 0, len(req.AttachmentIds))
ids = append(ids, req.AttachmentIds...)
slices.SortFunc(ids, func(left, right uuid.UUID) int {
return bytes.Compare(left[:], right[:])
})
ids := req.AttachmentIds
if ids == nil {
ids = []uuid.UUID{}
}
payload, err := json.Marshal(struct {
Text string `json:"text"`