6 #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 struct object_id
*last_oid
= NULL
;
69 while (o
&& o
->type
== OBJ_TAG
)
70 if (((struct tag
*)o
)->tagged
) {
71 last_oid
= &((struct tag
*)o
)->tagged
->oid
;
72 o
= parse_object(last_oid
);
78 if (last_oid
&& is_promisor_object(last_oid
))
81 warnlen
= strlen(warn
);
82 error("missing object referenced by '%.*s'", warnlen
, warn
);
87 struct object
*deref_tag_noverify(struct object
*o
)
89 while (o
&& o
->type
== OBJ_TAG
) {
90 o
= parse_object(&o
->oid
);
91 if (o
&& o
->type
== OBJ_TAG
&& ((struct tag
*)o
)->tagged
)
92 o
= ((struct tag
*)o
)->tagged
;
99 struct tag
*lookup_tag(const struct object_id
*oid
)
101 struct object
*obj
= lookup_object(oid
->hash
);
103 return create_object(oid
->hash
, alloc_tag_node());
104 return object_as_type(obj
, OBJ_TAG
, 0);
107 static timestamp_t
parse_tag_date(const char *buf
, const char *tail
)
111 while (buf
< tail
&& *buf
++ != '>')
116 while (buf
< tail
&& *buf
++ != '\n')
120 /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
121 return parse_timestamp(dateptr
, NULL
, 10);
124 int parse_tag_buffer(struct tag
*item
, const void *data
, unsigned long size
)
126 struct object_id oid
;
128 const char *bufptr
= data
;
129 const char *tail
= bufptr
+ size
;
132 if (item
->object
.parsed
)
134 item
->object
.parsed
= 1;
136 if (size
< GIT_SHA1_HEXSZ
+ 24)
138 if (memcmp("object ", bufptr
, 7) || parse_oid_hex(bufptr
+ 7, &oid
, &bufptr
) || *bufptr
++ != '\n')
141 if (!starts_with(bufptr
, "type "))
144 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
145 if (!nl
|| sizeof(type
) <= (nl
- bufptr
))
147 memcpy(type
, bufptr
, nl
- bufptr
);
148 type
[nl
- bufptr
] = '\0';
151 if (!strcmp(type
, blob_type
)) {
152 item
->tagged
= (struct object
*)lookup_blob(&oid
);
153 } else if (!strcmp(type
, tree_type
)) {
154 item
->tagged
= (struct object
*)lookup_tree(&oid
);
155 } else if (!strcmp(type
, commit_type
)) {
156 item
->tagged
= (struct object
*)lookup_commit(&oid
);
157 } else if (!strcmp(type
, tag_type
)) {
158 item
->tagged
= (struct object
*)lookup_tag(&oid
);
160 error("Unknown type %s", type
);
164 if (bufptr
+ 4 < tail
&& starts_with(bufptr
, "tag "))
169 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
172 item
->tag
= xmemdupz(bufptr
, nl
- bufptr
);
175 if (bufptr
+ 7 < tail
&& starts_with(bufptr
, "tagger "))
176 item
->date
= parse_tag_date(bufptr
, tail
);
183 int parse_tag(struct tag
*item
)
185 enum object_type type
;
190 if (item
->object
.parsed
)
192 data
= read_object_file(&item
->object
.oid
, &type
, &size
);
194 return error("Could not read %s",
195 oid_to_hex(&item
->object
.oid
));
196 if (type
!= OBJ_TAG
) {
198 return error("Object %s not a tag",
199 oid_to_hex(&item
->object
.oid
));
201 ret
= parse_tag_buffer(item
, data
, size
);