/** * Update the digest computation by adding bytes to the message. * * @param in * input array of bytes. */ public void update(byte[] in) { update(in, 0, in.length); }
@Override public void write(byte[] in, int p, int n) throws IOException { md.update(in, p, n); out.write(in, p, n); } }
@Override public void write(int b) throws IOException { md.update((byte) b); out.write(b); }
private byte[] computeHash(InputStream in, long length) throws IOException { SHA1 contentDigest = SHA1.newInstance(); final byte[] contentReadBuffer = state.contentReadBuffer; contentDigest.update(hblob); contentDigest.update((byte) ' '); long sz = length; if (sz == 0) { contentDigest.update((byte) '0'); } else { final int bufn = contentReadBuffer.length; int p = bufn; do { contentReadBuffer[--p] = digits[(int) (sz % 10)]; sz /= 10; } while (sz > 0); contentDigest.update(contentReadBuffer, p, bufn - p); } contentDigest.update((byte) 0); for (;;) { final int r = in.read(contentReadBuffer); if (r <= 0) break; contentDigest.update(contentReadBuffer, 0, r); sz += r; } if (sz != length) return zeroid; return contentDigest.digest(); }
/** * Compute the name of an object, without inserting it. * * @param type * type code of the object to store. * @param data * complete content of the object. * @param off * first position within {@code data}. * @param len * number of bytes to copy from {@code data}. * @return the name of the object. */ public ObjectId idFor(int type, byte[] data, int off, int len) { SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); md.update(data, off, len); return md.toObjectId(); }
throws IOException { SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(objectType)); md.update((byte) ' '); md.update(Constants.encodeASCII(length)); md.update((byte) 0); byte[] buf = buffer(); while (length > 0) { if (n < 0) throw new EOFException(JGitText.get().unexpectedEndOfInput); md.update(buf, 0, n); length -= n;
/** {@inheritDoc} */ @Override public ObjectId insert(int type, long len, InputStream in) throws IOException { byte[] buf = insertBuffer(len); if (len <= buf.length) { IO.readFully(in, buf, 0, (int) len); return insert(type, buf, 0, (int) len); } long offset = beginObject(type, len); SHA1 md = digest(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); while (0 < len) { int n = in.read(buf, 0, (int) Math.min(buf.length, len)); if (n <= 0) throw new EOFException(); md.update(buf, 0, n); packOut.compress.write(buf, 0, n); len -= n; } packOut.compress.finish(); return endObject(md.toObjectId(), offset); }
/** {@inheritDoc} */ @Override public ObjectId insert(int type, long len, InputStream in) throws IOException { byte[] buf = buffer(); if (len <= buf.length) { IO.readFully(in, buf, 0, (int) len); return insert(type, buf, 0, (int) len); } long offset = beginObject(type, len); SHA1 md = digest(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); while (0 < len) { int n = in.read(buf, 0, (int) Math.min(buf.length, len)); if (n <= 0) { throw new EOFException(); } md.update(buf, 0, n); packOut.compress.write(buf, 0, n); len -= n; } packOut.compress.finish(); return endObject(md.toObjectId(), offset); }
byte[] finishPack() throws IOException { // Overwrite placeholder header with actual object count, then hash. This // method intentionally uses direct seek/write calls rather than the // wrappers which keep track of atEnd. This leaves atEnd, the file // pointer, and out's counter in an inconsistent state; that's ok, since // this method closes the file anyway. try { file.seek(0); out.write(hdrBuf, 0, writePackHeader(hdrBuf, objectList.size())); byte[] buf = buffer(); SHA1 md = digest().reset(); file.seek(0); while (true) { int r = file.read(buf); if (r < 0) { break; } md.update(buf, 0, r); } byte[] packHash = md.digest(); out.write(packHash, 0, packHash.length); return packHash; } finally { close(); } }
private ObjectId computeName(List<PackedObjectInfo> list) { SHA1 md = digest().reset(); byte[] buf = buffer(); for (PackedObjectInfo otp : list) { otp.copyRawTo(buf, 0); md.update(buf, 0, OBJECT_ID_LENGTH); } return ObjectId.fromRaw(md.digest()); }
private void whole(long pos, int type, long sz) throws IOException { SHA1 objectDigest = objectHasher.reset(); objectDigest.update(Constants.encodedTypeString(type)); objectDigest.update((byte) ' '); objectDigest.update(Constants.encodeASCII(sz)); objectDigest.update((byte) 0); if (r <= 0) break; objectDigest.update(readBuffer, 0, r); checker.update(readBuffer, 0, r); cnt += r; } else { data = inflateAndReturn(Source.INPUT, sz); objectDigest.update(data); objectDigest.digest(tempObjectId); verifySafeObject(tempObjectId, type, data);
/** * Update the digest computation by adding bytes to the message. * * @param in * input array of bytes. */ public void update(byte[] in) { update(in, 0, in.length); }
@Override public void write(int b) throws IOException { md.update((byte) b); out.write(b); }
@Override public void write(byte[] in, int p, int n) throws IOException { md.update(in, p, n); out.write(in, p, n); } }
private byte[] computeHash(InputStream in, long length) throws IOException { SHA1 contentDigest = SHA1.newInstance(); final byte[] contentReadBuffer = state.contentReadBuffer; contentDigest.update(hblob); contentDigest.update((byte) ' '); long sz = length; if (sz == 0) { contentDigest.update((byte) '0'); } else { final int bufn = contentReadBuffer.length; int p = bufn; do { contentReadBuffer[--p] = digits[(int) (sz % 10)]; sz /= 10; } while (sz > 0); contentDigest.update(contentReadBuffer, p, bufn - p); } contentDigest.update((byte) 0); for (;;) { final int r = in.read(contentReadBuffer); if (r <= 0) break; contentDigest.update(contentReadBuffer, 0, r); sz += r; } if (sz != length) return zeroid; return contentDigest.digest(); }
/** * Compute the name of an object, without inserting it. * * @param type * type code of the object to store. * @param data * complete content of the object. * @param off * first position within {@code data}. * @param len * number of bytes to copy from {@code data}. * @return the name of the object. */ public ObjectId idFor(int type, byte[] data, int off, int len) { SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); md.update(data, off, len); return md.toObjectId(); }
/** {@inheritDoc} */ @Override public ObjectId insert(int type, long len, InputStream in) throws IOException { byte[] buf = buffer(); if (len <= buf.length) { IO.readFully(in, buf, 0, (int) len); return insert(type, buf, 0, (int) len); } long offset = beginObject(type, len); SHA1 md = digest(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); while (0 < len) { int n = in.read(buf, 0, (int) Math.min(buf.length, len)); if (n <= 0) { throw new EOFException(); } md.update(buf, 0, n); packOut.compress.write(buf, 0, n); len -= n; } packOut.compress.finish(); return endObject(md.toObjectId(), offset); }
byte[] finishPack() throws IOException { // Overwrite placeholder header with actual object count, then hash. This // method intentionally uses direct seek/write calls rather than the // wrappers which keep track of atEnd. This leaves atEnd, the file // pointer, and out's counter in an inconsistent state; that's ok, since // this method closes the file anyway. try { file.seek(0); out.write(hdrBuf, 0, writePackHeader(hdrBuf, objectList.size())); byte[] buf = buffer(); SHA1 md = digest().reset(); file.seek(0); while (true) { int r = file.read(buf); if (r < 0) { break; } md.update(buf, 0, r); } byte[] packHash = md.digest(); out.write(packHash, 0, packHash.length); return packHash; } finally { close(); } }
private ObjectId computeName(List<PackedObjectInfo> list) { SHA1 md = digest().reset(); byte[] buf = buffer(); for (PackedObjectInfo otp : list) { otp.copyRawTo(buf, 0); md.update(buf, 0, OBJECT_ID_LENGTH); } return ObjectId.fromRaw(md.digest()); }