| 177 | } |
| 178 | |
| 179 | func (v *version) Validate() error { |
| 180 | // time must be set after a commit |
| 181 | if v.commitHash != "" && v.unixTime == 0 { |
| 182 | return fmt.Errorf("unix time not set") |
| 183 | } |
| 184 | |
| 185 | if text.Empty(v.name) && text.Empty(v.login) { |
| 186 | return fmt.Errorf("either name or login should be set") |
| 187 | } |
| 188 | if !text.SafeOneLine(v.name) { |
| 189 | return fmt.Errorf("name has unsafe characters") |
| 190 | } |
| 191 | |
| 192 | if !text.SafeOneLine(v.login) { |
| 193 | return fmt.Errorf("login has unsafe characters") |
| 194 | } |
| 195 | |
| 196 | if !text.SafeOneLine(v.email) { |
| 197 | return fmt.Errorf("email has unsafe characters") |
| 198 | } |
| 199 | |
| 200 | if v.avatarURL != "" && !text.ValidUrl(v.avatarURL) { |
| 201 | return fmt.Errorf("avatarUrl is not a valid URL") |
| 202 | } |
| 203 | |
| 204 | if len(v.nonce) > 64 { |
| 205 | return fmt.Errorf("nonce is too big") |
| 206 | } |
| 207 | if len(v.nonce) < 20 { |
| 208 | return fmt.Errorf("nonce is too small") |
| 209 | } |
| 210 | |
| 211 | for _, k := range v.keys { |
| 212 | if err := k.Validate(); err != nil { |
| 213 | return errors.Wrap(err, "invalid key") |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return nil |
| 218 | } |
| 219 | |
| 220 | // Write will serialize and store the version as a git blob and return |
| 221 | // its hash |