package taskplan import "unicode/utf8" type SourceRef struct { Kind string `json:"kind"` ID string `json:"id"` Hash string `json:"hash"` Revision int64 `json:"revision"` } type AnswerResult struct { Body string `json:"body"` Sources []SourceRef `json:"sources"` } func ValidateAnswer(a AnswerResult) error { if !utf8.ValidString(a.Body) || len(a.Body) == 0 || len(a.Body) > 16<<10 || len(a.Sources) == 0 || len(a.Sources) > 100 { return ErrInvalid } seen := map[SourceRef]bool{} for _, s := range a.Sources { if s.Kind == "" || len(s.Kind) > 64 || s.ID == "" || len(s.ID) > 256 || s.Revision < 1 || len(s.Hash) != 64 || seen[s] { return ErrInvalid } for _, c := range s.Hash { if !(c >= '0' && c <= '9' || c >= 'a' && c <= 'f') { return ErrInvalid } } seen[s] = true } return nil } type RenderDiffFile struct { Path string `json:"path"` Before []byte `json:"before"` After []byte `json:"after"` BeforeMode uint32 `json:"before_mode"` AfterMode uint32 `json:"after_mode"` }