Download raw body.
do not hardcode digest length when parsing packed trees
On 2024/07/18 12:49:53 +0200, Omar Polo <op@omarpolo.com> wrote: > On 2024/07/17 23:32:33 +0200, Christian Weisgerber <naddy@mips.inka.de> wrote: > > Omar Polo: > > > > > the subject says it all. there are a few upcoming diff where I'm > > > replacing SHA1_DIGEST{,_STRING}_LENGTH with the right length derived > > > with got_hash_digest{,_string}_length() but this is a bit more delicate. > > > > Since you are already in the process of abstracting the hash details, > > I think it would help -portable if all the interfacing with the > > operating system SHA functions were completely encapsulated in > > lib/hash.c, and everything else referenced only got_*() functions > > and GOT_* defines. > > Yeah, this is my plan actually. sha1.h and sha2.h are needed because > some GOT_* defines are in terms of SHA*_DIGEST{,_STRING}_LENGTH but I > see no reason why we couldn't just hardcode the values and get rid of > these includes in the vast majority of the files. > > I didn't know it was problematic for -portable to deal with these > includes, so I left the dependency everywhere. But I'll find a way to > fix it. > > > To rephrase, the goal should be to remove > > > > #include <sha1.h> > > #include <sha2.h> > > > > from all other source files. > > sha2.h should be pretty easy to remove from all the files, just hardcode > the defines in lib/got_lib_hash.h and include/got_object.h. sha1.h > defines are still used widely in gotd and in the network code, and for > that it'll take me longer "fix". It's actually not that easy since inside the struct got_hash we're using SHA1_CTX and SHA2_CTX. I'm not sure how to make them opaque. I'd like to avoid having to allocate memory in got_hash_init(). The easiest way out of this would be to include sha1.h and sha2.h from got_lib_hash.h, but we usually avoid including headers from headers.
do not hardcode digest length when parsing packed trees