13
13
* permissions and limitations under the License.
14
14
*/
15
15
16
- package software .amazon .awssdk .http . auth . aws . internal . signer . checksums ;
16
+ package software .amazon .awssdk .checksums ;
17
17
18
18
import java .nio .ByteBuffer ;
19
19
import 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 ;
21
28
22
29
/**
23
30
* Extension of {@link Checksum} to support checksums and checksum validations used by the SDK that are not provided by the JDK.
24
31
*/
25
- @ SdkInternalApi
32
+ @ SdkProtectedApi
26
33
public interface SdkChecksum extends Checksum {
27
34
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
+
28
58
/**
29
59
* Returns the computed checksum in a byte array rather than the long provided by {@link #getValue()}.
30
60
*
@@ -49,7 +79,6 @@ default void update(byte[] b) {
49
79
update (b , 0 , b .length );
50
80
}
51
81
52
-
53
82
/**
54
83
* Updates the current checksum with the bytes from the specified buffer.
55
84
* <p>
0 commit comments