git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: madmarcos <fru574@my.utsa.edu>
To: git@vger.kernel.org
Subject: calculating a git packfile sha1 checksum in java
Date: Tue, 22 Mar 2011 02:27:24 -0700 (PDT)	[thread overview]
Message-ID: <1300786044816-6195501.post@n2.nabble.com> (raw)

I am learning about the Git packfile and currently trying to reproduce (in
Java) what I believe to be the SHA1 20-byte checksum for the entire
packfile. I take the byte array from, and including, the "PACK" 4-byte
header to the end of the last packaged object's compressed data. Everything
I have read indicates that the next 20 bytes is the SHA1 checksum for the
entire packfile.

The 20-byte checksum that is part of the byte array received from Git is:
B910248BF9B63AC53595E3835CA57BDAF08DA830

I use the following to calculate my own SHA1 checksum: 
crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(testData);
byte [] result = crypt.digest();

My result ends up as: B910248BF9B63AC53595E3835CA57BDAF08DA813

I am baffled at how only the last byte of my result can be different from
Git's (if I am using the correct part of the byte stream). If the only
problem was the range of data passed to digest() then the entire calculated
checksum would most likely look different.

Any ideas?

Note: I use the same code to generate test SHA1 ids for each contained
object and they match the references in the tree objects. This problem
currently only involves calculating the checksum over the entire packfile.

--
View this message in context: http://git.661346.n2.nabble.com/calculating-a-git-packfile-sha1-checksum-in-java-tp6195501p6195501.html
Sent from the git mailing list archive at Nabble.com.

             reply	other threads:[~2011-03-22  9:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-22  9:27 madmarcos [this message]
2011-03-22 14:01 ` calculating a git packfile sha1 checksum in java Shawn Pearce
     [not found]   ` <AANLkTiniKOzzwZhJ5GN4nf8AWRTsT6bbMeK4s5XqvH42@mail.gmail.com>
2011-03-22 20:58     ` madmarcos
2011-03-22 21:10       ` Nicolas Pitre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1300786044816-6195501.post@n2.nabble.com \
    --to=fru574@my.utsa.edu \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).