1313 * permissions and limitations under the License.
1414 */
1515
16- package software .amazon .awssdk .http . auth . aws . internal . signer . checksums ;
16+ package software .amazon .awssdk .checksums ;
1717
1818import java .nio .ByteBuffer ;
1919import java .util .zip .Checksum ;
20- import software .amazon .awssdk .annotations .SdkInternalApi ;
20+ import software .amazon .awssdk .annotations .SdkProtectedApi ;
21+ import software .amazon .awssdk .checksums .internal .Crc32CChecksum ;
22+ import software .amazon .awssdk .checksums .internal .Crc32Checksum ;
23+ import software .amazon .awssdk .checksums .internal .Crc64NvmeChecksum ;
24+ import software .amazon .awssdk .checksums .internal .Md5Checksum ;
25+ import software .amazon .awssdk .checksums .internal .Sha1Checksum ;
26+ import software .amazon .awssdk .checksums .internal .Sha256Checksum ;
27+ import software .amazon .awssdk .checksums .spi .ChecksumAlgorithm ;
2128
2229/**
2330 * Extension of {@link Checksum} to support checksums and checksum validations used by the SDK that are not provided by the JDK.
2431 */
25- @ SdkInternalApi
32+ @ SdkProtectedApi
2633public interface SdkChecksum extends Checksum {
2734
35+ /**
36+ * Returns an {@link SdkChecksum} based on the {@link ChecksumAlgorithm} provided.
37+ * UnsupportedOperationException will be thrown for unsupported algorithm.
38+ */
39+ static SdkChecksum forAlgorithm (ChecksumAlgorithm algorithm ) {
40+ switch (algorithm .algorithmId ()) {
41+ case "CRC32C" :
42+ return new Crc32CChecksum ();
43+ case "CRC32" :
44+ return new Crc32Checksum ();
45+ case "SHA1" :
46+ return new Sha1Checksum ();
47+ case "SHA256" :
48+ return new Sha256Checksum ();
49+ case "MD5" :
50+ return new Md5Checksum ();
51+ case "CRC64NVME" :
52+ return new Crc64NvmeChecksum ();
53+ default :
54+ throw new UnsupportedOperationException ("Unsupported checksum algorithm: " + algorithm );
55+ }
56+ }
57+
2858 /**
2959 * Returns the computed checksum in a byte array rather than the long provided by {@link #getValue()}.
3060 *
@@ -49,7 +79,6 @@ default void update(byte[] b) {
4979 update (b , 0 , b .length );
5080 }
5181
52-
5382 /**
5483 * Updates the current checksum with the bytes from the specified buffer.
5584 * <p>
0 commit comments