Skip to content

Commit

Permalink
verify-tag: factor out signature detection
Browse files Browse the repository at this point in the history
into tag.h/c for later reuse and modification.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael J Gruber authored and gitster committed Nov 10, 2010
1 parent c8525c3 commit ac58c4c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 2 additions & 8 deletions builtin/verify-tag.c
Expand Up @@ -17,13 +17,11 @@ static const char * const verify_tag_usage[] = {
NULL
};

#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"

static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
{
struct child_process gpg;
const char *args_gpg[] = {"gpg", "--verify", "FILE", "-", NULL};
char path[PATH_MAX], *eol;
char path[PATH_MAX];
size_t len;
int fd, ret;

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

/* find the length without signature */
len = 0;
while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) {
eol = memchr(buf + len, '\n', size - len);
len += eol ? eol - (buf + len) + 1 : size - len;
}
len = parse_signature(buf, size);
if (verbose)
write_in_full(1, buf, len);

Expand Down
13 changes: 13 additions & 0 deletions tag.c
Expand Up @@ -4,6 +4,8 @@
#include "tree.h"
#include "blob.h"

#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"

const char *tag_type = "tag";

struct object *deref_tag(struct object *o, const char *warn, int warnlen)
Expand Down Expand Up @@ -133,3 +135,14 @@ int parse_tag(struct tag *item)
free(data);
return ret;
}

size_t parse_signature(const char *buf, unsigned long size)
{
char *eol;
size_t len = 0;
while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) {
eol = memchr(buf + len, '\n', size - len);
len += eol ? eol - (buf + len) + 1 : size - len;
}
return len;
}
1 change: 1 addition & 0 deletions tag.h
Expand Up @@ -16,5 +16,6 @@ extern struct tag *lookup_tag(const unsigned char *sha1);
extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size);
extern int parse_tag(struct tag *item);
extern struct object *deref_tag(struct object *, const char *, int);
extern size_t parse_signature(const char *buf, unsigned long size);

#endif /* TAG_H */

0 comments on commit ac58c4c

Please sign in to comment.