diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2022-11-16 10:15:30 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-11-16 10:15:30 +0100 |
commit | 0fb9d26eff27f3843a389e3b41e8331fee412a6c (patch) | |
tree | 3ca60d7aa31834504d22e87d55d59dd1db585c55 /org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1Native.java | |
parent | f288de7490ee9bc82f688de40295f14adb18e454 (diff) | |
parent | 1cd9a1f804fce2278cd6f8bfaf9b9a27310f5f8c (diff) | |
download | jgit-0fb9d26eff27f3843a389e3b41e8331fee412a6c.tar.gz jgit-0fb9d26eff27f3843a389e3b41e8331fee412a6c.zip |
Merge branch 'stable-6.3'
* stable-6.3:
[benchmarks] Remove profiler configuration
Add SHA1 benchmark
[benchmarks] Set version of maven-compiler-plugin to 3.8.1
Fix running JMH benchmarks
Add option to allow using JDK's SHA1 implementation
Fix API breakage caused by extracting WorkTreeUpdater
Extract Exception -> HTTP status code mapping for reuse
Don't handle internal git errors as an HTTP error
Ignore IllegalStateException if JVM is already shutting down
Allow to perform PackedBatchRefUpdate without locking loose refs
Change-Id: Ib58879be292c54a2a7f4936ac0986997985c822b
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1Native.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1Native.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1Native.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1Native.java new file mode 100644 index 0000000000..4599ac0cba --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1Native.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2022, Matthias Sohn <matthias.sohn@sap.com> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.util.sha1; + +import java.security.MessageDigest; + +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.MutableObjectId; +import org.eclipse.jgit.lib.ObjectId; + +/** + * SHA1 implementation using native implementation from JDK. It doesn't support + * collision detection but is faster than the pure Java implementation. + */ +class SHA1Native extends SHA1 { + + private final MessageDigest md; + + SHA1Native() { + md = Constants.newMessageDigest(); + } + + @Override + public void update(byte b) { + md.update(b); + } + + @Override + public void update(byte[] in) { + md.update(in); + } + + @Override + public void update(byte[] in, int p, int len) { + md.update(in, p, len); + } + + @Override + public byte[] digest() throws Sha1CollisionException { + return md.digest(); + } + + @Override + public ObjectId toObjectId() throws Sha1CollisionException { + return ObjectId.fromRaw(md.digest()); + } + + @Override + public void digest(MutableObjectId id) throws Sha1CollisionException { + id.fromRaw(md.digest()); + } + + @Override + public SHA1 reset() { + md.reset(); + return this; + } + + @Override + public SHA1 setDetectCollision(boolean detect) { + return this; + } + + @Override + public boolean hasCollision() { + return false; + } +} |