|
1 | 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0. |
3 | 3 |
|
4 | | -import struct Foundation.Data |
5 | 4 | import AwsCChecksums |
6 | 5 |
|
| 6 | +import struct Foundation.Data |
| 7 | + |
7 | 8 | extension Data { |
8 | | - |
| 9 | + |
9 | 10 | /// Computes the CRC32 over data. |
10 | 11 | /// - Parameter previousCrc32: Pass 0 in the previousCrc32 parameter as an initial value unless continuing to update a running crc in a subsequent call. |
11 | 12 | public func computeCRC32(previousCrc32: UInt32 = 0) -> UInt32 { |
12 | 13 | self.withUnsafeBytes { bufferPointer in |
13 | | - return aws_checksums_crc32(bufferPointer.baseAddress?.assumingMemoryBound(to: UInt8.self), |
14 | | - Int32(count), |
15 | | - previousCrc32) |
| 14 | + return aws_checksums_crc32_ex( |
| 15 | + bufferPointer.baseAddress?.assumingMemoryBound(to: UInt8.self), |
| 16 | + count, |
| 17 | + previousCrc32) |
16 | 18 | } |
17 | 19 | } |
18 | | - |
| 20 | + |
19 | 21 | /// Computes the crc32c over data. |
20 | 22 | /// - Parameter previousCrc32c: Pass 0 in the previousCrc32c parameter as an initial value unless continuing to update a running crc in a subsequent call. |
21 | 23 | public func computeCRC32C(previousCrc32c: UInt32 = 0) -> UInt32 { |
22 | 24 | self.withUnsafeBytes { bufferPointer in |
23 | | - return aws_checksums_crc32c(bufferPointer.baseAddress?.assumingMemoryBound(to: UInt8.self), |
24 | | - Int32(count), |
25 | | - previousCrc32c) |
26 | | - } |
| 25 | + return aws_checksums_crc32c_ex( |
| 26 | + bufferPointer.baseAddress?.assumingMemoryBound(to: UInt8.self), |
| 27 | + count, |
| 28 | + previousCrc32c) |
| 29 | + } |
27 | 30 | } |
28 | | - |
| 31 | + |
| 32 | + /// Computes the CRC64NVME over data. |
| 33 | + /// - Parameter previousCrc64Nvme: Pass 0 in the previousCrc64Nvme parameter as an initial value unless continuing to update a running crc in a subsequent call. |
| 34 | + public func computeCRC64Nvme(previousCrc64Nvme: UInt64 = 0) -> UInt64 { |
| 35 | + self.withUnsafeBytes { bufferPointer in |
| 36 | + return aws_checksums_crc64nvme_ex( |
| 37 | + bufferPointer.baseAddress?.assumingMemoryBound(to: UInt8.self), |
| 38 | + count, |
| 39 | + previousCrc64Nvme) |
| 40 | + } |
| 41 | + } |
| 42 | + |
29 | 43 | } |
0 commit comments