8000 Sort methods. · apache/commons-codec@be0c8da · GitHub
Skip to content

Commit be0c8da

Browse files
committed
Sort methods.
1 parent 95212be commit be0c8da

2 files changed

Lines changed: 214 additions & 214 deletions

File tree

src/main/java/org/apache/commons/codec/digest/DigestUtils.java

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,6 @@ public static MessageDigest getSha384Digest() {
320320
return getDigest(MessageDigestAlgorithms.SHA_384);
321321
}
322322

323-
/**
324-
* Returns an SHA-512 digest.
325-
*
326-
* @return An SHA-512 digest instance.
327-
* @throws IllegalArgumentException
328-
* when a {@link NoSuchAlgorithmException} is caught, which should never happen
329-
* because SHA-512 is a built-in algorithm
330-
* @see MessageDigestAlgorithms#SHA_512
331-
*/
332-
public static MessageDigest getSha512Digest() {
333-
return getDigest(MessageDigestAlgorithms.SHA_512);
334-
}
335-
336323
/**
337324
* Returns an SHA-512/224 digest.
338325
*
@@ -357,6 +344,19 @@ public static MessageDigest getSha512_256Digest() {
357344
return getDigest(MessageDigestAlgorithms.SHA_512_256);
358345
}
359346

347+
/**
348+
* Returns an SHA-512 digest.
349+
*
350+
* @return An SHA-512 digest instance.
351+
* @throws IllegalArgumentException
352+
* when a {@link NoSuchAlgorithmException} is caught, which should never happen
353+
* because SHA-512 is a built-in algorithm
354+
* @see MessageDigestAlgorithms#SHA_512
355+
*/
356+
public static MessageDigest getSha512Digest() {
357+
return getDigest(MessageDigestAlgorithms.SHA_512);
358+
}
359+
360360
/**
361361
* Returns an SHA-1 digest.
362362
*
@@ -1114,41 +1114,41 @@ public static byte[] sha512(final byte[] data) {
11141114
}
11151115

11161116
/**
1117-
* Calculates the SHA-512/224 digest and returns the value as a {@code byte[]}.
1117+
* Calculates the SHA-512 digest and returns the value as a {@code byte[]}.
11181118
*
11191119
* @param data
11201120
* Data to digest
1121-
* @return SHA-512/224 digest
1122-
* @since 1.14
1121+
* @return SHA-512 digest
1122+
* @throws IOException
1123+
* On error reading from the stream
1124+
* @since 1.4
11231125
*/
1124-
public static byte[] sha512_224(final byte[] data) {
1125-
return getSha512_224Digest().digest(data);
1126+
public static byte[] sha512(final InputStream data) throws IOException {
1127+
return digest(getSha512Digest(), data);
11261128
}
11271129

11281130
/**
1129-
* Calculates the SHA-512/256 digest and returns the value as a {@code byte[]}.
1131+
* Calculates the SHA-512 digest and returns the value as a {@code byte[]}.
11301132
*
11311133
* @param data
1132-
* Data to digest
1133-
* @return SHA-512/256 digest
1134-
* @since 1.14
1134+
* Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
1135+
* @return SHA-512 digest
1136+
* @since 1.4
11351137
*/
1136-
public static byte[] sha512_256(final byte[] data) {
1137-
return getSha512_256Digest().digest(data);
1138+
public static byte[] sha512(final String data) {
1139+
return sha512(StringUtils.getBytesUtf8(data));
11381140
}
11391141

11401142
/**
1141-
* Calculates the SHA-512 digest and returns the value as a {@code byte[]}.
1143+
* Calculates the SHA-512/224 digest and returns the value as a {@code byte[]}.
11421144
*
11431145
* @param data
11441146
* Data to digest
1145-
* @return SHA-512 digest
1146-
* @throws IOException
1147-
* On error reading from the stream
1148-
* @since 1.4
1147+
* @return SHA-512/224 digest
1148+
* @since 1.14
11491149
*/
1150-
public static byte[] sha512(final InputStream data) throws IOException {
1151-
return digest(getSha512Digest(), data);
1150+
public static byte[] sha512_224(final byte[] data) {
1151+
return getSha512_224Digest().digest(data);
11521152
}
11531153

11541154
/**
@@ -1166,77 +1166,91 @@ public static byte[] sha512_224(final InputStream data) throws IOException {
11661166
}
11671167

11681168
/**
1169-
* Calculates the SHA-512/256 digest and returns the value as a {@code byte[]}.
1169+
* Calculates the SHA-512/224 digest and returns the value as a {@code byte[]}.
1170+
*
1171+
* @param data
1172+
* Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
1173+
* @return SHA-512/224 digest
1174+
* @since 1.14
1175+
*/
1176+
public static byte[] sha512_224(final String data) {
1177+
return sha512_224(StringUtils.getBytesUtf8(data));
1178+
}
1179+
1180+
/**
1181+
* Calculates the SHA-512/224 digest and returns the value as a hex string.
11701182
*
11711183
* @param data
11721184
* Data to digest
1173-
* @return SHA-512/256 digest
1174-
* @throws IOException
1175-
* On error reading from the stream
1185+
* @return SHA-512/224 digest as a hex string
11761186
* @since 1.14
11771187
*/
1178-
public static byte[] sha512_256(final InputStream data) throws IOException {
1179-
return digest(getSha512_256Digest(), data);
1188+
public static String sha512_224Hex(final byte[] data) {
1189+
return Hex.encodeHexString(sha512_224(data));
11801190
}
11811191

11821192
/**
1183-
* Calculates the SHA-512 digest and returns the value as a {@code byte[]}.
1193+
* Calculates the SHA-512/224 digest and returns the value as a hex string.
11841194
*
11851195
* @param data
1186-
* Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
1187-
* @return SHA-512 digest
1188-
* @since 1.4
1196+
* Data to digest
1197+
* @return SHA-512/224 digest as a hex string
1198+
* @throws IOException
1199+
* On error reading from the stream
1200+
* @since 1.14
11891201
*/
1190-
public static byte[] sha512(final String data) {
1191-
return sha512(StringUtils.getBytesUtf8(data));
1202+
public static String sha512_224Hex(final InputStream data) throws IOException {
1203+
return Hex.encodeHexString(sha512_224(data));
11921204
}
11931205

11941206
/**
1195-
* Calculates the SHA-512/224 digest and returns the value as a {@code byte[]}.
1207+
* Calculates the SHA-512/224 digest and returns the value as a hex string.
11961208
*
11971209
* @param data
1198-
* Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
1199-
* @return SHA-512/224 digest
1210+
* Data to digest
1211+
* @return SHA-512/224 digest as a hex string
12001212
* @since 1.14
12011213
*/
1202-
public static byte[] sha512_224(final String data) {
1203-
return sha512_224(StringUtils.getBytesUtf8(data));
1214+
public static String sha512_224Hex(final String data) {
1215+
return Hex.encodeHexString(sha512_224(data));
12041216
}
12051217

12061218
/**
12071219
* Calculates the SHA-512/256 digest and returns the value as a {@code byte[]}.
12081220
*
12091221
* @param data
1210-
* Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
1211-
* @return SHA-512/224 digest
1222+
* Data to digest
1223+
* @return SHA-512/256 digest
12121224
* @since 1.14
12131225
*/
1214-
public static byte[] sha512_256(final String data) {
1215-
return sha512_256(StringUtils.getBytesUtf8(data));
1226+
public static byte[] sha512_256(final byte[] data) {
1227+
return getSha512_256Digest().digest(data);
12161228
}
12171229

12181230
/**
1219-
* Calculates the SHA-512 digest and returns the value as a hex string.
1231+
* Calculates the SHA-512/256 digest and returns the value as a {@code byte[]}.
12201232
*
12211233
* @param data
12221234
* Data to digest
1223-
* @return SHA-512 digest as a hex string
1224-
* @since 1.4
1235+
* @return SHA-512/256 digest
1236+
* @throws IOException
1237+
* On error reading from the stream
1238+
* @since 1.14
12251239
*/
1226-
public static String sha512Hex(final byte[] data) {
1227-
return Hex.encodeHexString(sha512(data));
1240+
public static byte[] sha512_256(final InputStream data) throws IOException {
1241+
return digest(getSha512_256Digest(), data);
12281242
}
12291243

12301244
/**
1231-
* Calculates the SHA-512/224 digest and returns the value as a hex string.
1245+
* Calculates the SHA-512/256 digest and returns the value as a {@code byte[]}.
12321246
*
12331247
* @param data
1234-
* Data to digest
1235-
* @return SHA-512/224 digest as a hex string
1248+
* Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
1249+
* @return SHA-512/224 digest
12361250
* @since 1.14
12371251
*/
1238-
public static String sha512_224Hex(final byte[] data) {
1239-
return Hex.encodeHexString(sha512_224(data));
1252+
public static byte[] sha512_256(final String data) {
1253+
return sha512_256(StringUtils.getBytesUtf8(data));
12401254
}
12411255

12421256
/**
@@ -1252,17 +1266,17 @@ public static String sha512_256Hex(final byte[] data) {
12521266
}
12531267

12541268
/**
1255-
* Calculates the SHA-512/224 digest and returns the value as a hex string.
1269+
* Calculates the SHA-512/256 digest and returns the value as a hex string.
12561270
*
12571271
* @param data
12581272
* Data to digest
1259-
* @return SHA-512/224 digest as a hex string
1273+
* @return SHA-512/256 digest as a hex string
12601274
* @throws IOException
12611275
* On error reading from the stream
12621276
* @since 1.14
12631277
*/
1264-
public static String sha512_224Hex(final InputStream data) throws IOException {
1265-
return Hex.encodeHexString(sha512_224(data));
1278+
public static String sha512_256Hex(final InputStream data) throws IOException {
1279+
return Hex.encodeHexString(sha512_256(data));
12661280
}
12671281

12681282
/**
@@ -1271,11 +1285,9 @@ public static String sha512_224Hex(final InputStream data) throws IOException {
12711285
* @param data
12721286
* Data to digest
12731287
* @return SHA-512/256 digest as a hex string
1274-
* @throws IOException
1275-
* On error reading from the stream
12761288
* @since 1.14
12771289
*/
1278-
public static String sha512_256Hex(final InputStream data) throws IOException {
1290+
public static String sha512_256Hex(final String data) {
12791291
return Hex.encodeHexString(sha512_256(data));
12801292
}
12811293

@@ -1285,11 +1297,9 @@ public static String sha512_256Hex(final InputStream data) throws IOException {
12851297
* @param data
12861298
* Data to digest
12871299
* @return SHA-512 digest as a hex string
1288-
* @throws IOException
1289-
* On error reading from the stream
12901300
* @since 1.4
12911301
*/
1292-
public static String sha512Hex(final InputStream data) throws IOException {
1302+
public static String sha512Hex(final byte[] data) {
12931303
return Hex.encodeHexString(sha512(data));
12941304
}
12951305

@@ -1299,34 +1309,24 @@ public static String sha512Hex(final InputStream data) throws IOException {
12991309
* @param data
13001310
* Data to digest
13011311
* @return SHA-512 digest as a hex string
1312+
* @throws IOException
1313+
* On error reading from the stream
13021314
* @since 1.4
13031315
*/
1304-
public static String sha512Hex(final String data) {
1316+
public static String sha512Hex(final InputStream data) throws IOException {
13051317
return Hex.encodeHexString(sha512(data));
13061318
}
13071319

13081320
/**
1309-
* Calculates the SHA-512/224 digest and returns the value as a hex string.
1310-
*
1311-
* @param data
1312-
* Data to digest
1313-
* @return SHA-512/224 digest as a hex string
1314-
* @since 1.14
1315-
*/
1316-
public static String sha512_224Hex(final String data) {
1317-
return Hex.encodeHexString(sha512_224(data));
1318-
}
1319-
1320-
/**
1321-
* Calculates the SHA-512/256 digest and returns the value as a hex string.
1321+
* Calculates the SHA-512 digest and returns the value as a hex string.
13221322
*
13231323
* @param data
13241324
* Data to digest
1325-
* @return SHA-512/256 digest as a hex string
1326-
* @since 1.14
1325+
* @return SHA-512 digest as a hex string
1326+
* @since 1.4
13271327
*/
1328-
public static String sha512_256Hex(final String data) {
1329-
return Hex.encodeHexString(sha512_256(data));
1328+
public static String sha512Hex(final String data) {
1329+
return Hex.encodeHexString(sha512(data));
13301330
}
13311331

13321332
/**
@@ -1682,33 +1682,33 @@ public String digestAsHex(final File data) throws IOException {
16821682
}
16831683

16841684
/**
1685-
* Reads through a File and returns the digest for the data
1685+
* Reads through an InputStream and returns the digest for the data
16861686
*
16871687
* @param data
16881688
* Data to digest
1689-
* @param options
1690-
* options How to open the file
16911689
* @return the digest as a hex string
16921690
* @throws IOException
16931691
* On error reading from the stream
16941692
* @since 1.11
16951693
*/
1696-
public String digestAsHex(final Path data, final OpenOption... options) throws IOException {
1697-
return Hex.encodeHexString(digest(data, options));
1694+
public String digestAsHex(final InputStream data) throws IOException {
1695+
return Hex.encodeHexString(digest(data));
16981696
}
16991697

17001698
/**
1701-
* Reads through an InputStream and returns the digest for the data
1699+
* Reads through a File and returns the digest for the data
17021700
*
17031701
* @param data
17041702
* Data to digest
1703+
* @param options
1704+
* options How to open the file
17051705
* @return the digest as a hex string
17061706
* @throws IOException
17071707
* On error reading from the stream
17081708
* @since 1.11
17091709
*/
1710-
public String digestAsHex(final InputStream data) throws IOException {
1711-
return Hex.encodeHexString(digest(data));
1710+
public String digestAsHex(final Path data, final OpenOption... options) throws IOException {
1711+
return Hex.encodeHexString(digest(data, options));
17121712
}
17131713

17141714
/**

0 commit comments

Comments
 (0)