Skip to content

Commit ac58c4c

Browse files
Michael J Grubergitster
authored andcommitted
verify-tag: factor out signature detection
into tag.h/c for later reuse and modification. Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c8525c3 commit ac58c4c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

builtin/verify-tag.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ static const char * const verify_tag_usage[] = {
1717
NULL
1818
};
1919

20-
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
21-
2220
static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
2321
{
2422
struct child_process gpg;
2523
const char *args_gpg[] = {"gpg", "--verify", "FILE", "-", NULL};
26-
char path[PATH_MAX], *eol;
24+
char path[PATH_MAX];
2725
size_t len;
2826
int fd, ret;
2927

@@ -37,11 +35,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
3735
close(fd);
3836

3937
/* find the length without signature */
40-
len = 0;
41-
while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) {
42-
eol = memchr(buf + len, '\n', size - len);
43-
len += eol ? eol - (buf + len) + 1 : size - len;
44-
}
38+
len = parse_signature(buf, size);
4539
if (verbose)
4640
write_in_full(1, buf, len);
4741

tag.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "tree.h"
55
#include "blob.h"
66

7+
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
8+
79
const char *tag_type = "tag";
810

911
struct object *deref_tag(struct object *o, const char *warn, int warnlen)
@@ -133,3 +135,14 @@ int parse_tag(struct tag *item)
133135
free(data);
134136
return ret;
135137
}
138+
139+
size_t parse_signature(const char *buf, unsigned long size)
140+
{
141+
char *eol;
142+
size_t len = 0;
143+
while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) {
144+
eol = memchr(buf + len, '\n', size - len);
145+
len += eol ? eol - (buf + len) + 1 : size - len;
146+
}
147+
return len;
148+
}

tag.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ extern struct tag *lookup_tag(const unsigned char *sha1);
1616
extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size);
1717
extern int parse_tag(struct tag *item);
1818
extern struct object *deref_tag(struct object *, const char *, int);
19+
extern size_t parse_signature(const char *buf, unsigned long size);
1920

2021
#endif /* TAG_H */

0 commit comments

Comments
 (0)