Download this file
| 1 | package taskplan |
| 2 | |
| 3 | import "unicode/utf8" |
| 4 | |
| 5 | type SourceRef struct { |
| 6 | Kind string `json:"kind"` |
| 7 | ID string `json:"id"` |
| 8 | Hash string `json:"hash"` |
| 9 | Revision int64 `json:"revision"` |
| 10 | } |
| 11 | type AnswerResult struct { |
| 12 | Body string `json:"body"` |
| 13 | Sources []SourceRef `json:"sources"` |
| 14 | } |
| 15 | |
| 16 | func ValidateAnswer(a AnswerResult) error { |
| 17 | if !utf8.ValidString(a.Body) || len(a.Body) == 0 || len(a.Body) > 16<<10 || len(a.Sources) == 0 || len(a.Sources) > 100 { |
| 18 | return ErrInvalid |
| 19 | } |
| 20 | seen := map[SourceRef]bool{} |
| 21 | for _, s := range a.Sources { |
| 22 | if s.Kind == "" || len(s.Kind) > 64 || s.ID == "" || len(s.ID) > 256 || s.Revision < 1 || len(s.Hash) != 64 || seen[s] { |
| 23 | return ErrInvalid |
| 24 | } |
| 25 | for _, c := range s.Hash { |
| 26 | if !(c >= '0' && c <= '9' || c >= 'a' && c <= 'f') { |
| 27 | return ErrInvalid |
| 28 | } |
| 29 | } |
| 30 | seen[s] = true |
| 31 | } |
| 32 | return nil |
| 33 | } |
| 34 | |
| 35 | type RenderDiffFile struct { |
| 36 | Path string `json:"path"` |
| 37 | Before []byte `json:"before"` |
| 38 | After []byte `json:"after"` |
| 39 | BeforeMode uint32 `json:"before_mode"` |
| 40 | AfterMode uint32 `json:"after_mode"` |
| 41 | } |
| 42 | |