7 #include "gpg-interface.h"
9 const char *tag_type = "tag";
11 static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
13 struct signature_check sigc;
17 memset(&sigc, 0, sizeof(sigc));
19 payload_size = parse_signature(buf, size);
21 if (size == payload_size) {
22 if (flags & GPG_VERIFY_VERBOSE)
23 write_in_full(1, buf, payload_size);
24 return error("no signature found");
27 ret = check_signature(buf, payload_size, buf + payload_size,
28 size - payload_size, &sigc);
30 if (!(flags & GPG_VERIFY_OMIT_STATUS))
31 print_signature_buffer(&sigc, flags);
33 signature_check_clear(&sigc);
37 int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
40 enum object_type type;
45 type = oid_object_info(the_repository, oid, NULL);
47 return error("%s: cannot verify a non-tag object of type %s.",
50 find_unique_abbrev(oid, DEFAULT_ABBREV),
53 buf = read_object_file(oid, &type, &size);
55 return error("%s: unable to read file.",
58 find_unique_abbrev(oid, DEFAULT_ABBREV));
60 ret = run_gpg_verify(buf, size, flags);
66 struct object *deref_tag(struct object *o, const char *warn, int warnlen)
68 while (o && o->type == OBJ_TAG)
69 if (((struct tag *)o)->tagged)
70 o = parse_object(&((struct tag *)o)->tagged->oid);
75 warnlen = strlen(warn);
76 error("missing object referenced by '%.*s'", warnlen, warn);
81 struct object *deref_tag_noverify(struct object *o)
83 while (o && o->type == OBJ_TAG) {
84 o = parse_object(&o->oid);
85 if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
86 o = ((struct tag *)o)->tagged;
93 struct tag *lookup_tag(const struct object_id *oid)
95 struct object *obj = lookup_object(oid->hash);
97 return create_object(the_repository, oid->hash,
98 alloc_tag_node(the_repository));
99 return object_as_type(obj, OBJ_TAG, 0);
102 static timestamp_t parse_tag_date(const char *buf, const char *tail)
106 while (buf < tail && *buf++ != '>')
111 while (buf < tail && *buf++ != '\n')
115 /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
116 return parse_timestamp(dateptr, NULL, 10);
119 void release_tag_memory(struct tag *t)
123 t->object.parsed = 0;
127 int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
129 struct object_id oid;
131 const char *bufptr = data;
132 const char *tail = bufptr + size;
135 if (item->object.parsed)
137 item->object.parsed = 1;
139 if (size < GIT_SHA1_HEXSZ + 24)
141 if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\n')
144 if (!starts_with(bufptr, "type "))
147 nl = memchr(bufptr, '\n', tail - bufptr);
148 if (!nl || sizeof(type) <= (nl - bufptr))
150 memcpy(type, bufptr, nl - bufptr);
151 type[nl - bufptr] = '\0';
154 if (!strcmp(type, blob_type)) {
155 item->tagged = (struct object *)lookup_blob(&oid);
156 } else if (!strcmp(type, tree_type)) {
157 item->tagged = (struct object *)lookup_tree(&oid);
158 } else if (!strcmp(type, commit_type)) {
159 item->tagged = (struct object *)lookup_commit(&oid);
160 } else if (!strcmp(type, tag_type)) {
161 item->tagged = (struct object *)lookup_tag(&oid);
163 error("Unknown type %s", type);
167 if (bufptr + 4 < tail && starts_with(bufptr, "tag "))
172 nl = memchr(bufptr, '\n', tail - bufptr);
175 item->tag = xmemdupz(bufptr, nl - bufptr);
178 if (bufptr + 7 < tail && starts_with(bufptr, "tagger "))
179 item->date = parse_tag_date(bufptr, tail);
186 int parse_tag(struct tag *item)
188 enum object_type type;
193 if (item->object.parsed)
195 data = read_object_file(&item->object.oid, &type, &size);
197 return error("Could not read %s",
198 oid_to_hex(&item->object.oid));
199 if (type != OBJ_TAG) {
201 return error("Object %s not a tag",
202 oid_to_hex(&item->object.oid));
204 ret = parse_tag_buffer(item, data, size);