See RFC 3174.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
SHA1 implementations available in JGit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract byte[]
digest()
Finish the digest and return the resulting hash.abstract void
Finish the digest and return the resulting hash.abstract boolean
Check if a collision was detected.static SHA1
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
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.
-
Constructor Details
-
SHA1
public SHA1()
-
-
Method Details
-
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
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
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
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
Reset this instance to compute another hash.- Returns:
this
.
-
setDetectCollision
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.
-