Skip to content

Commit d7c6766

Browse files
committed
gpg-interface: move parse_signature() to where it should be
Our signed-tag objects set the standard format used by Git to store GPG-signed payload (i.e. the payload followed by its detached signature) [*1*], and it made sense to have a helper to find the boundary between the payload and its signature in tag.c back then. Newer code added later to parse other kinds of objects that learned to use the same format to store GPG-signed payload (e.g. signed commits), however, kept using the helper from the same location. Move it to gpg-interface; the helper is no longer about signed tag, but it is how our code and data interact with GPG. [Reference] *1* http://thread.gmane.org/gmane.linux.kernel/297998/focus=1383 Signed-off-by: Junio C Hamano <[email protected]>
1 parent a50e7ca commit d7c6766

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

gpg-interface.c

+21
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
static char *configured_signing_key;
88
static const char *gpg_program = "gpg";
99

10+
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
11+
#define PGP_MESSAGE "-----BEGIN PGP MESSAGE-----"
12+
1013
void signature_check_clear(struct signature_check *sigc)
1114
{
1215
free(sigc->payload);
@@ -57,6 +60,24 @@ void parse_gpg_output(struct signature_check *sigc)
5760
}
5861
}
5962

63+
/*
64+
* Look at GPG signed content (e.g. a signed tag object), whose
65+
* payload is followed by a detached signature on it. Return the
66+
* offset where the embedded detached signature begins, or the end of
67+
* the data when there is no such signature.
68+
*/
69+
size_t parse_signature(const char *buf, unsigned long size)
70+
{
71+
char *eol;
72+
size_t len = 0;
73+
while (len < size && !starts_with(buf + len, PGP_SIGNATURE) &&
74+
!starts_with(buf + len, PGP_MESSAGE)) {
75+
eol = memchr(buf + len, '\n', size - len);
76+
len += eol ? eol - (buf + len) + 1 : size - len;
77+
}
78+
return len;
79+
}
80+
6081
void set_signing_key(const char *key)
6182
{
6283
free(configured_signing_key);

gpg-interface.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct signature_check {
2020
};
2121

2222
extern void signature_check_clear(struct signature_check *sigc);
23+
extern size_t parse_signature(const char *buf, unsigned long size);
2324
extern void parse_gpg_output(struct signature_check *);
2425
extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
2526
extern int verify_signed_buffer(const char *payload, size_t payload_size, const char *signature, size_t signature_size, struct strbuf *gpg_output, struct strbuf *gpg_status);

tag.c

-20
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#include "tree.h"
55
#include "blob.h"
66

7-
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
8-
#define PGP_MESSAGE "-----BEGIN PGP MESSAGE-----"
9-
107
const char *tag_type = "tag";
118

129
struct object *deref_tag(struct object *o, const char *warn, int warnlen)
@@ -143,20 +140,3 @@ int parse_tag(struct tag *item)
143140
free(data);
144141
return ret;
145142
}
146-
147-
/*
148-
* Look at a signed tag object, and return the offset where
149-
* the embedded detached signature begins, or the end of the
150-
* data when there is no such signature.
151-
*/
152-
size_t parse_signature(const char *buf, unsigned long size)
153-
{
154-
char *eol;
155-
size_t len = 0;
156-
while (len < size && !starts_with(buf + len, PGP_SIGNATURE) &&
157-
!starts_with(buf + len, PGP_MESSAGE)) {
158-
eol = memchr(buf + len, '\n', size - len);
159-
len += eol ? eol - (buf + len) + 1 : size - len;
160-
}
161-
return len;
162-
}

tag.h

-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long si
1717
extern int parse_tag(struct tag *item);
1818
extern struct object *deref_tag(struct object *, const char *, int);
1919
extern struct object *deref_tag_noverify(struct object *);
20-
extern size_t parse_signature(const char *buf, unsigned long size);
2120

2221
#endif /* TAG_H */

0 commit comments

Comments
 (0)