summaryrefslogtreecommitdiff
path: root/src/object.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-11-29 13:44:42 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2021-11-30 22:45:13 -0500
commit9f03ebd14b6beb00a9bed52c0568a13f8d5ebb08 (patch)
treedcec3efee630f9c38e15433302e5c6faec65e517 /src/object.c
parentfc1a3f456540dfc4dc143b322b943a4264658d56 (diff)
downloadlibgit2-ethomson/object_validation.tar.gz
object: introduce a raw content validation functionethomson/object_validation
Users may want to validate raw object content; provide them a function to do so.
Diffstat (limited to 'src/object.c')
-rw-r--r--src/object.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/object.c b/src/object.c
index 7e6ad3aa2..7bc256fce 100644
--- a/src/object.c
+++ b/src/object.c
@@ -567,3 +567,35 @@ bool git_object__is_valid(
return true;
}
+
+int git_object_rawcontent_is_valid(
+ int *valid,
+ const char *buf,
+ size_t len,
+ git_object_t type)
+{
+ git_object *obj = NULL;
+ int error;
+
+ GIT_ASSERT_ARG(valid);
+ GIT_ASSERT_ARG(buf);
+
+ /* Blobs are always valid; don't bother parsing. */
+ if (type == GIT_OBJECT_BLOB) {
+ *valid = 1;
+ return 0;
+ }
+
+ error = git_object__from_raw(&obj, buf, len, type);
+ git_object_free(obj);
+
+ if (error == 0) {
+ *valid = 1;
+ return 0;
+ } else if (error == GIT_EINVALID) {
+ *valid = 0;
+ return 0;
+ }
+
+ return error;
+}