| 1202 | } |
| 1203 | |
| 1204 | int parse_buffer_signed_by_header(const char *buffer, |
| 1205 | unsigned long size, |
| 1206 | struct strbuf *payload, |
| 1207 | struct strbuf *signature, |
| 1208 | const struct git_hash_algo *algop) |
| 1209 | { |
| 1210 | int in_signature = 0, saw_signature = 0, other_signature = 0; |
| 1211 | const char *line, *tail, *p; |
| 1212 | const char *gpg_sig_header = gpg_sig_headers[hash_algo_by_ptr(algop)]; |
| 1213 | |
| 1214 | line = buffer; |
| 1215 | tail = buffer + size; |
| 1216 | while (line < tail) { |
| 1217 | const char *sig = NULL; |
| 1218 | const char *next = memchr(line, '\n', tail - line); |
| 1219 | |
| 1220 | next = next ? next + 1 : tail; |
| 1221 | if (in_signature && line[0] == ' ') |
| 1222 | sig = line + 1; |
| 1223 | else if (skip_prefix(line, gpg_sig_header, &p) && |
| 1224 | *p == ' ') { |
| 1225 | sig = line + strlen(gpg_sig_header) + 1; |
| 1226 | other_signature = 0; |
| 1227 | } |
| 1228 | else if (starts_with(line, "gpgsig")) |
| 1229 | other_signature = 1; |
| 1230 | else if (other_signature && line[0] != ' ') |
| 1231 | other_signature = 0; |
| 1232 | if (sig) { |
| 1233 | strbuf_add(signature, sig, next - sig); |
| 1234 | saw_signature = 1; |
| 1235 | in_signature = 1; |
| 1236 | } else { |
| 1237 | if (*line == '\n') |
| 1238 | /* dump the whole remainder of the buffer */ |
| 1239 | next = tail; |
| 1240 | if (!other_signature) |
| 1241 | strbuf_add(payload, line, next - line); |
| 1242 | in_signature = 0; |
| 1243 | } |
| 1244 | line = next; |
| 1245 | } |
| 1246 | return saw_signature; |
| 1247 | } |
| 1248 | |
| 1249 | int remove_signature(struct strbuf *buf) |
| 1250 | { |
no test coverage detected