Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
# limitations under the License.

* text=auto

# Preserve bytes used by fixed checksum and Git object ID test vectors.
/src/test/resources/Crc16Test/license.txt text eol=lf
/src/test/resources/DigestUtilsTest/**/*.txt text eol=lf
17 changes: 13 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,26 @@ permissions:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
max-parallel: 20
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
java: [ 8, 11, 17, 21, 25, 27 ]
experimental: [false]
include:
- java: 28-ea
- os: ubuntu-latest
java: 28-ea
experimental: true

- os: windows-latest
java: 28-ea
experimental: true
- os: macos-latest
java: 28-ea
experimental: true

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -51,7 +60,7 @@ jobs:
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: 'temurin'
distribution: ${{ runner.os == 'macOS' && matrix.java == '8' && 'zulu' || 'temurin' }}
java-version: ${{ matrix.java }}
- name: Build with Maven
run: mvn --errors --show-version --batch-mode --no-transfer-progress
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Stop BaseNCodecInputStream from reading the underlying stream after codec EOF, preventing unnecessary reads and blocking after padding in lenient Base32 and Base64 decoding.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Compute Digest ALL and * standard-input digests in a single pass with bounded buffering, removing the mark/reset input-size limit.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Keep BaseNCodecInputStream.available() positive after codec EOF while output remains buffered.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make GitIdentifiers filesystem tests account for unavailable POSIX attributes, symbolic-link creation privileges, and platform-specific link target paths.</action>
<!-- ADD -->
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 105 to 107.</action>
Expand Down
8 changes: 4 additions & 4 deletions src/main/javadoc/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ <h1><img src="org/apache/commons/codec/doc-files/leaf.svg" style="height: 1em; p
<td><a href="org/apache/commons/codec/digest/Blake3.html">Blake3</a></td>
<td>Provides a pure Java implementation of the <a href="https://github.com/BLAKE3-team/BLAKE3">Blake3 hash function</a> which can be used for
computing <a href="https://en.wikipedia.org/wiki/Cryptographic_hash_function">cryptographic hashes</a> (message digests) which are extensible to
arbitrary output lengths (known as an <i>extensible-output function</i> or <i>XOF</i>), computing <a
href="https://en.wikipedia.org/wiki/Message_authentication_code">message authentication codes</a> using a 32 byte (256-bit) secret key, computing
arbitrary output lengths (known as an <i>extensible-output function</i> or <i>XOF</i>), computing
<a href="https://en.wikipedia.org/wiki/Message_authentication_code">message authentication codes</a> using a 32 byte (256-bit) secret key, computing
subkeys from a primary key using a <a href="https://en.wikipedia.org/wiki/Key_derivation_function">key derivation function</a>, and can be used as the
basis for a <a href="https://en.wikipedia.org/wiki/Cryptographically-secure_pseudorandom_number_generator"> cryptographically-secure pseudorandom
number generator</a>. <strong>WARNING:</strong> Blake3 is <em>not</em> a password hashing algorithm! An algorithm such as <a
href="https://github.com/P-H-C/phc-winner-argon2">Argon2</a> is more appropriate for password hashing.
number generator</a>. <strong>WARNING:</strong> Blake3 is <em>not</em> a password hashing algorithm! An algorithm such as
<a href="https://github.com/P-H-C/phc-winner-argon2">Argon2</a> is more appropriate for password hashing.
</td>
</tr>
<tr>
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/apache/commons/codec/digest/Crc16Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
import static org.junit.jupiter.api.Assertions.assertNotSame;

import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.function.Supplier;
import java.util.zip.Checksum;

import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.io.file.PathUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.function.Uncheck;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -38,7 +37,8 @@
*/
class Crc16Test {

private static final String BIG_TEXT = Uncheck.get(() -> PathUtils.readString(Paths.get("LICENSE.txt"), StandardCharsets.US_ASCII));
private static final String BIG_TEXT = Uncheck.get(() -> IOUtils.resourceToString("Crc16Test/license.txt",
StandardCharsets.US_ASCII, Crc16Test.class.getClassLoader()));
private static final byte[] TEST_BYTES = "123456789".getBytes(StandardCharsets.US_ASCII);
private static final int TEST_BYTES_LEN = TEST_BYTES.length;

Expand Down
55 changes: 29 additions & 26 deletions src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.RandomAccessFileMode;
import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -377,10 +375,6 @@ RandomAccessFile getTestRandomAccessFile() {
return testRandomAccessFileWrapper;
}

private boolean isJava9Plus() {
return SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9);
}

@BeforeEach
void setUp() throws Exception {
new Random().nextBytes(testData);
Expand Down Expand Up @@ -439,27 +433,36 @@ void testGetDigests() {
}

@Test
void testGetDigestsJava9() {
if (isJava9Plus()) {
void testGetMessageDigest() {
final DigestUtils digestUtils = new DigestUtils(MessageDigestAlgorithms.MD5);
assertNotNull(digestUtils.getMessageDigest());
assertEquals(MessageDigestAlgorithms.MD5, digestUtils.getMessageDigest().getAlgorithm());
}

@Test
void testGetSha3Digests() {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_224)) {
assertEquals("SHA3-224", DigestUtils.getSha3_224Digest().getAlgorithm());
assertEquals("SHA3-256", DigestUtils.getSha3_256Digest().getAlgorithm());
assertEquals("SHA3-384", DigestUtils.getSha3_384Digest().getAlgorithm());
assertEquals("SHA3-512", DigestUtils.getSha3_512Digest().getAlgorithm());
} else {
assertThrows(IllegalArgumentException.class, DigestUtils::getSha3_224Digest);
}
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_256)) {
assertEquals("SHA3-256", DigestUtils.getSha3_256Digest().getAlgorithm());
} else {
assertThrows(IllegalArgumentException.class, DigestUtils::getSha3_256Digest);
}
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_384)) {
assertEquals("SHA3-384", DigestUtils.getSha3_384Digest().getAlgorithm());
} else {
assertThrows(IllegalArgumentException.class, DigestUtils::getSha3_384Digest);
}
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_512)) {
assertEquals("SHA3-512", DigestUtils.getSha3_512Digest().getAlgorithm());
} else {
assertThrows(IllegalArgumentException.class, DigestUtils::getSha3_512Digest);
}
}

@Test
void testGetMessageDigest() {
final DigestUtils digestUtils = new DigestUtils(MessageDigestAlgorithms.MD5);
assertNotNull(digestUtils.getMessageDigest());
assertEquals(MessageDigestAlgorithms.MD5, digestUtils.getMessageDigest().getAlgorithm());
}

/**
* Tests SHAKE digest lookup according to runtime algorithm availability.
*
Expand Down Expand Up @@ -694,7 +697,7 @@ void testSha256HexInputStream() throws IOException {

@Test
void testSha3_224() {
if (isJava9Plus()) {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_224)) {
// Examples from https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
//
// https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-224_Msg0.pdf
Expand All @@ -706,7 +709,7 @@ void testSha3_224() {

@Test
void testSha3_224HexInputStream() throws IOException {
if (isJava9Plus()) {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_224)) {
assertEquals(DigestUtils.sha3_224Hex(testData), DigestUtils.sha3_224Hex(new ByteArrayInputStream(testData)));
} else {
assertThrows(IllegalArgumentException.class, () -> DigestUtils.sha3_224Hex(new ByteArrayInputStream(testData)));
Expand All @@ -715,7 +718,7 @@ void testSha3_224HexInputStream() throws IOException {

@Test
void testSha3_256() {
if (isJava9Plus()) {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_256)) {
// Examples from https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
//
// https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-256_Msg0.pdf
Expand All @@ -727,7 +730,7 @@ void testSha3_256() {

@Test
void testSha3_256HexInputStream() throws IOException {
if (isJava9Plus()) {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_256)) {
assertEquals(DigestUtils.sha3_256Hex(testData), DigestUtils.sha3_256Hex(new ByteArrayInputStream(testData)));
} else {
assertThrows(IllegalArgumentException.class, () -> DigestUtils.sha3_256Hex(new ByteArrayInputStream(testData)));
Expand All @@ -736,7 +739,7 @@ void testSha3_256HexInputStream() throws IOException {

@Test
void testSha3_384() {
if (isJava9Plus()) {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_384)) {
// Examples from https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
//
// https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-384_Msg0.pdf
Expand All @@ -749,7 +752,7 @@ void testSha3_384() {

@Test
void testSha3_384HexInputStream() throws IOException {
if (isJava9Plus()) {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_384)) {
assertEquals(DigestUtils.sha3_384Hex(testData), DigestUtils.sha3_384Hex(new ByteArrayInputStream(testData)));
} else {
assertThrows(IllegalArgumentException.class, () -> DigestUtils.sha3_384Hex(new ByteArrayInputStream(testData)));
Expand All @@ -758,7 +761,7 @@ void testSha3_384HexInputStream() throws IOException {

@Test
void testSha3_512() {
if (isJava9Plus()) {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_512)) {
// Examples from https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
//
// https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-512_Msg0.pdf
Expand All @@ -771,7 +774,7 @@ void testSha3_512() {

@Test
void testSha3_512HexInputStream() throws IOException {
if (isJava9Plus()) {
if (DigestUtils.isAvailable(MessageDigestAlgorithms.SHA3_512)) {
assertEquals(DigestUtils.sha3_512Hex(testData), DigestUtils.sha3_512Hex(new ByteArrayInputStream(testData)));
} else {
assertThrows(IllegalArgumentException.class, () -> DigestUtils.sha3_512Hex(new ByteArrayInputStream(testData)));
Expand Down
Loading
Loading