Top Description Inners Fields Constructors Methods
org.eclipse.jgit.util.sha1

public abstract Class SHA1

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.util.sha1.SHA1Java, org.eclipse.jgit.util.sha1.SHA1Native
Imports
java.io.IOException, java.security.MessageDigest, org.eclipse.jgit.errors.ConfigInvalidException, org.eclipse.jgit.lib.ConfigConstants, .MutableObjectId, .ObjectId, org.eclipse.jgit.util.SystemReader

SHA-1 interface from FIPS 180-1 / RFC 3174 with optional collision detection. Some implementations may not support collision detection.

See RFC 3174.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
SHA1.Sha1Implementation

SHA1 implementations available in JGit

Field Summary

Modifier and TypeField and Description
private static final SHA1.Sha1Implementation

Constructor Summary

AccessConstructor and Description
public
SHA1()

Method Summary

Modifier and TypeMethod and Description
public abstract byte[]

Returns:

the bytes for the resulting hash.
digest
()

Finish the digest and return the resulting hash.

public abstract void
digest(MutableObjectId
destination to copy the digest to.
id
)

Finish the digest and return the resulting hash.

private static SHA1.Sha1Implementation
private static SHA1.Sha1Implementation
public abstract boolean

Returns:

true if a likely collision was detected.
hasCollision
()

Check if a collision was detected.

public static SHA1

Returns:

a new context to compute a SHA-1 hash of data.
newInstance
()

Create a new context to compute a SHA-1 hash of data.

public abstract SHA1

Returns:

this.
reset
()

Reset this instance to compute another hash.

public abstract SHA1

Returns:

this
setDetectCollision
(boolean
a boolean.
detect
)

Enable likely collision detection.

public abstract ObjectId

Returns:

the ObjectId for the resulting hash.
toObjectId
()

Finish the digest and return the resulting hash.

public abstract void
update(byte
a byte.
b
)

Update the digest computation by adding a byte.

public abstract void
update(byte[]
input array of bytes.
in
)

Update the digest computation by adding bytes to the message.

public abstract void
update(byte[]
input array of bytes.
in
,
int
offset to start at from in.
p
,
int
number of bytes to hash.
len
)

Update the digest computation by adding bytes to the message.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

SHA1_IMPLEMENTATIONback to summary
private static final SHA1.Sha1Implementation SHA1_IMPLEMENTATION

Constructor Detail

SHA1back to summary
public SHA1()

Method Detail

digestback to summary
public abstract byte[] digest() throws Sha1CollisionException

Finish the digest and return the resulting hash.

Once digest() is called, this instance should be discarded.

Returns:byte[]

the bytes for the resulting hash.

Exceptions
Sha1CollisionException:
if a collision was detected and safeHash is false.
digestback to summary
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:MutableObjectId

destination to copy the digest to.

Exceptions
Sha1CollisionException:
if a collision was detected and safeHash is false.
fromConfigback to summary
private static SHA1.Sha1Implementation fromConfig()
getImplementationback to summary
private static SHA1.Sha1Implementation getImplementation()
hasCollisionback to summary
public abstract boolean hasCollision()

Check if a collision was detected. This method only returns an accurate result after the digest was obtained through digest(), digest(MutableObjectId) or toObjectId(), as the hashing function must finish processing to know the final state.

Implementations not supporting collision detection always return false.

Returns:boolean

true if a likely collision was detected.

newInstanceback to summary
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 property org.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:SHA1

a new context to compute a SHA-1 hash of data.

resetback to summary
public abstract SHA1 reset()

Reset this instance to compute another hash.

Returns:SHA1

this.

setDetectCollisionback to summary
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:boolean

a boolean.

Returns:SHA1

this

toObjectIdback to summary
public abstract ObjectId toObjectId() throws Sha1CollisionException

Finish the digest and return the resulting hash.

Once digest() is called, this instance should be discarded.

Returns:ObjectId

the ObjectId for the resulting hash.

Exceptions
Sha1CollisionException:
if a collision was detected and safeHash is false.
updateback to summary
public abstract void update(byte b)

Update the digest computation by adding a byte.

Parameters
b:byte

a byte.

updateback to summary
public abstract void update(byte[] in)

Update the digest computation by adding bytes to the message.

Parameters
in:byte[]

input array of bytes.

updateback to summary
public abstract void update(byte[] in, int p, int len)

Update the digest computation by adding bytes to the message.

Parameters
in:byte[]

input array of bytes.

p:int

offset to start at from in.

len:int

number of bytes to hash.

org.eclipse.jgit.util.sha1 back to summary

public final Enum SHA1.Sha1Implementation

extends Enum<SHA1.Sha1Implementation>
Class Inheritance

SHA1 implementations available in JGit
Since
5.13.2

Field Summary

Modifier and TypeField and Description
private final String
public static final SHA1.Sha1Implementation
JAVA

SHA1Java implemented in Java, supports collision detection.

public static final SHA1.Sha1Implementation
JDKNATIVE

Native implementation based on JDK's MessageDigest.

Constructor Summary

AccessConstructor and Description
private
Sha1Implementation(Class<T> implClass)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.

public static SHA1.Sha1Implementation
public static SHA1.Sha1Implementation[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

implClassNameback to summary
private final String implClassName
JAVAback to summary
public static final SHA1.Sha1Implementation JAVA

SHA1Java implemented in Java, supports collision detection.

JDKNATIVEback to summary
public static final SHA1.Sha1Implementation JDKNATIVE

Native implementation based on JDK's MessageDigest.

Constructor Detail

Sha1Implementationback to summary
private Sha1Implementation(Class<T> implClass)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static SHA1.Sha1Implementation valueOf(String name)
valuesback to summary
public static SHA1.Sha1Implementation[] values()