Class SHA1
- java.lang.Object
-
- org.eclipse.jgit.util.sha1.SHA1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SHA1.Sha1Implementation
SHA1 implementations available in JGit
-
Constructor Summary
Constructors Constructor Description SHA1()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract byte[]
digest()
Finish the digest and return the resulting hash.abstract void
digest(MutableObjectId id)
Finish the digest and return the resulting hash.abstract boolean
hasCollision()
Check if a collision was detected.static SHA1
newInstance()
Create a new context to compute a SHA-1 hash of data.abstract SHA1
reset()
Reset this instance to compute another hash.abstract SHA1
setDetectCollision(boolean detect)
Enable likely collision detection.abstract ObjectId
toObjectId()
Finish the digest and return the resulting hash.abstract void
update(byte b)
Update the digest computation by adding a byte.abstract void
update(byte[] in)
Update the digest computation by adding bytes to the message.abstract void
update(byte[] in, int p, int len)
Update the digest computation by adding bytes to the message.
-
-
-
Method Detail
-
newInstance
public static SHA1 newInstance()
Create a new context to compute a SHA-1 hash of data.If
core.sha1Implementation = jdkNative
in the user level global git configuration or the system propertyorg.eclipse.jgit.util.sha1.implementation = jdkNative
it will create an object using the implementation in the JDK. If both are set the system property takes precedence. Otherwise the pure Java implementation will be used which supports collision detection but is slower.- Returns:
- a new context to compute a SHA-1 hash of data.
-
update
public abstract void update(byte b)
Update the digest computation by adding a byte.- Parameters:
b
- a byte.
-
update
public abstract void update(byte[] in)
Update the digest computation by adding bytes to the message.- Parameters:
in
- input array of bytes.
-
update
public abstract void update(byte[] in, int p, int len)
Update the digest computation by adding bytes to the message.- Parameters:
in
- input array of bytes.p
- offset to start at fromin
.len
- number of bytes to hash.
-
digest
public abstract byte[] digest() throws Sha1CollisionException
Finish the digest and return the resulting hash.Once
digest()
is called, this instance should be discarded.- Returns:
- the bytes for the resulting hash.
- Throws:
Sha1CollisionException
- if a collision was detected and safeHash is false.
-
toObjectId
public abstract ObjectId toObjectId() throws Sha1CollisionException
Finish the digest and return the resulting hash.Once
digest()
is called, this instance should be discarded.- Returns:
- the ObjectId for the resulting hash.
- Throws:
Sha1CollisionException
- if a collision was detected and safeHash is false.
-
digest
public abstract void digest(MutableObjectId id) throws Sha1CollisionException
Finish the digest and return the resulting hash.Once
digest()
is called, this instance should be discarded.- Parameters:
id
- destination to copy the digest to.- Throws:
Sha1CollisionException
- if a collision was detected and safeHash is false.
-
reset
public abstract SHA1 reset()
Reset this instance to compute another hash.- Returns:
this
.
-
setDetectCollision
public abstract SHA1 setDetectCollision(boolean detect)
Enable likely collision detection.Default for implementations supporting collision detection is
true
.Implementations not supporting collision detection ignore calls to this method.
- Parameters:
detect
- a boolean.- Returns:
this
-
hasCollision
public abstract boolean hasCollision()
Check if a collision was detected. This method only returns an accurate result after the digest was obtained throughdigest()
,digest(MutableObjectId)
ortoObjectId()
, as the hashing function must finish processing to know the final state.Implementations not supporting collision detection always return
false
.- Returns:
true
if a likely collision was detected.
-
-