@aws-sdk/checksums
Advanced tools
+5
| /** | ||
| * Do not edit: | ||
| * This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
| */ | ||
| export * from "./dist-types/submodules/crc/index"; |
+5
| /** | ||
| * Do not edit: | ||
| * This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
| */ | ||
| module.exports = require("./dist-cjs/submodules/crc/index.js"); |
| const { Crc32, Crc32Js, Crc32Node } = require("@smithy/core/checksum"); | ||
| exports.Crc32 = Crc32; | ||
| exports.Crc32Js = Crc32Js; | ||
| exports.Crc32Node = Crc32Node; | ||
| const T = new Uint32Array(256); | ||
| for (let i = 0; i < 256; ++i) { | ||
| let c = i; | ||
| for (let j = 0; j < 8; ++j) { | ||
| c = c & 1 ? 0x82f63b78 ^ (c >>> 1) : c >>> 1; | ||
| } | ||
| T[i] = c >>> 0; | ||
| } | ||
| class Crc32cJs { | ||
| digestLength = 4; | ||
| crc = 0xffff_ffff; | ||
| update(data) { | ||
| let crc = this.crc; | ||
| for (let i = 0; i < data.length; ++i) { | ||
| crc = (crc >>> 8) ^ T[(crc ^ data[i]) & 0xff]; | ||
| } | ||
| this.crc = crc; | ||
| } | ||
| async digest() { | ||
| const value = (this.crc ^ 0xffff_ffff) >>> 0; | ||
| const out = new Uint8Array(4); | ||
| out[0] = value >>> 24; | ||
| out[1] = (value >>> 16) & 0xff; | ||
| out[2] = (value >>> 8) & 0xff; | ||
| out[3] = value & 0xff; | ||
| return out; | ||
| } | ||
| reset() { | ||
| this.crc = 0xffff_ffff; | ||
| } | ||
| } | ||
| const Crc32cNode = Crc32cJs; | ||
| const crc64NvmeCrtContainer = { | ||
| CrtCrc64Nvme: null, | ||
| }; | ||
| const generateCRC64NVMETable = () => { | ||
| const sliceLength = 8; | ||
| const tables = new Array(sliceLength); | ||
| for (let slice = 0; slice < sliceLength; slice++) { | ||
| const table = new Array(512); | ||
| for (let i = 0; i < 256; i++) { | ||
| let crc = BigInt(i); | ||
| for (let j = 0; j < 8 * (slice + 1); j++) { | ||
| if (crc & 1n) { | ||
| crc = (crc >> 1n) ^ 0x9a6c9329ac4bc9b5n; | ||
| } | ||
| else { | ||
| crc = crc >> 1n; | ||
| } | ||
| } | ||
| table[i * 2] = Number((crc >> 32n) & 0xffffffffn); | ||
| table[i * 2 + 1] = Number(crc & 0xffffffffn); | ||
| } | ||
| tables[slice] = new Uint32Array(table); | ||
| } | ||
| return tables; | ||
| }; | ||
| let CRC64_NVME_REVERSED_TABLE; | ||
| let t0, t1, t2, t3; | ||
| let t4, t5, t6, t7; | ||
| const ensureTablesInitialized = () => { | ||
| if (!CRC64_NVME_REVERSED_TABLE) { | ||
| CRC64_NVME_REVERSED_TABLE = generateCRC64NVMETable(); | ||
| [t0, t1, t2, t3, t4, t5, t6, t7] = CRC64_NVME_REVERSED_TABLE; | ||
| } | ||
| }; | ||
| class Crc64NvmeJs { | ||
| c1 = 0; | ||
| c2 = 0; | ||
| constructor() { | ||
| ensureTablesInitialized(); | ||
| this.reset(); | ||
| } | ||
| update(data) { | ||
| const len = data.length; | ||
| let i = 0; | ||
| let crc1 = this.c1; | ||
| let crc2 = this.c2; | ||
| while (i + 8 <= len) { | ||
| const idx0 = ((crc2 ^ data[i++]) & 255) << 1; | ||
| const idx1 = (((crc2 >>> 8) ^ data[i++]) & 255) << 1; | ||
| const idx2 = (((crc2 >>> 16) ^ data[i++]) & 255) << 1; | ||
| const idx3 = (((crc2 >>> 24) ^ data[i++]) & 255) << 1; | ||
| const idx4 = ((crc1 ^ data[i++]) & 255) << 1; | ||
| const idx5 = (((crc1 >>> 8) ^ data[i++]) & 255) << 1; | ||
| const idx6 = (((crc1 >>> 16) ^ data[i++]) & 255) << 1; | ||
| const idx7 = (((crc1 >>> 24) ^ data[i++]) & 255) << 1; | ||
| crc1 = t7[idx0] ^ t6[idx1] ^ t5[idx2] ^ t4[idx3] ^ t3[idx4] ^ t2[idx5] ^ t1[idx6] ^ t0[idx7]; | ||
| crc2 = | ||
| t7[idx0 + 1] ^ | ||
| t6[idx1 + 1] ^ | ||
| t5[idx2 + 1] ^ | ||
| t4[idx3 + 1] ^ | ||
| t3[idx4 + 1] ^ | ||
| t2[idx5 + 1] ^ | ||
| t1[idx6 + 1] ^ | ||
| t0[idx7 + 1]; | ||
| } | ||
| while (i < len) { | ||
| const idx = ((crc2 ^ data[i]) & 255) << 1; | ||
| crc2 = ((crc2 >>> 8) | ((crc1 & 255) << 24)) >>> 0; | ||
| crc1 = (crc1 >>> 8) ^ t0[idx]; | ||
| crc2 ^= t0[idx + 1]; | ||
| ++i; | ||
| } | ||
| this.c1 = crc1; | ||
| this.c2 = crc2; | ||
| } | ||
| async digest() { | ||
| const c1 = this.c1 ^ 4294967295; | ||
| const c2 = this.c2 ^ 4294967295; | ||
| return new Uint8Array([ | ||
| c1 >>> 24, | ||
| (c1 >>> 16) & 255, | ||
| (c1 >>> 8) & 255, | ||
| c1 & 255, | ||
| c2 >>> 24, | ||
| (c2 >>> 16) & 255, | ||
| (c2 >>> 8) & 255, | ||
| c2 & 255, | ||
| ]); | ||
| } | ||
| reset() { | ||
| this.c1 = 4294967295; | ||
| this.c2 = 4294967295; | ||
| } | ||
| } | ||
| class Crc64Nvme { | ||
| impl; | ||
| constructor() { | ||
| const Crt = crc64NvmeCrtContainer.CrtCrc64Nvme; | ||
| this.impl = Crt ? new Crt() : new Crc64NvmeJs(); | ||
| } | ||
| update(data) { | ||
| this.impl.update(data); | ||
| } | ||
| async digest() { | ||
| return this.impl.digest(); | ||
| } | ||
| reset() { | ||
| this.impl.reset(); | ||
| } | ||
| } | ||
| exports.Crc32c = Crc32cNode; | ||
| exports.Crc32cJs = Crc32cJs; | ||
| exports.Crc32cNode = Crc32cNode; | ||
| exports.Crc64Nvme = Crc64Nvme; | ||
| exports.Crc64NvmeJs = Crc64NvmeJs; | ||
| exports.crc64NvmeCrtContainer = crc64NvmeCrtContainer; |
| const { setFeature } = require("@aws-sdk/core/client"); | ||
| const { HttpRequest } = require("@smithy/core/protocols"); | ||
| const { isArrayBuffer, toUint8Array, createBufferedReadable, createChecksumStream } = require("@smithy/core/serde"); | ||
| const { Crc64Nvme, Crc32c, Crc32 } = require("@aws-sdk/checksums/crc"); | ||
| const { normalizeProvider } = require("@smithy/core/client"); | ||
| const RequestChecksumCalculation = { | ||
| WHEN_SUPPORTED: "WHEN_SUPPORTED", | ||
| WHEN_REQUIRED: "WHEN_REQUIRED", | ||
| }; | ||
| const DEFAULT_REQUEST_CHECKSUM_CALCULATION = RequestChecksumCalculation.WHEN_SUPPORTED; | ||
| const ResponseChecksumValidation = { | ||
| WHEN_SUPPORTED: "WHEN_SUPPORTED", | ||
| WHEN_REQUIRED: "WHEN_REQUIRED", | ||
| }; | ||
| const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.WHEN_SUPPORTED; | ||
| var ChecksumAlgorithm; | ||
| (function (ChecksumAlgorithm) { | ||
| ChecksumAlgorithm["MD5"] = "MD5"; | ||
| ChecksumAlgorithm["CRC32"] = "CRC32"; | ||
| ChecksumAlgorithm["CRC32C"] = "CRC32C"; | ||
| ChecksumAlgorithm["CRC64NVME"] = "CRC64NVME"; | ||
| ChecksumAlgorithm["SHA1"] = "SHA1"; | ||
| ChecksumAlgorithm["SHA256"] = "SHA256"; | ||
| })(ChecksumAlgorithm || (ChecksumAlgorithm = {})); | ||
| var ChecksumLocation; | ||
| (function (ChecksumLocation) { | ||
| ChecksumLocation["HEADER"] = "header"; | ||
| ChecksumLocation["TRAILER"] = "trailer"; | ||
| })(ChecksumLocation || (ChecksumLocation = {})); | ||
| const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; | ||
| var SelectorType; | ||
| (function (SelectorType) { | ||
| SelectorType["ENV"] = "env"; | ||
| SelectorType["CONFIG"] = "shared config entry"; | ||
| })(SelectorType || (SelectorType = {})); | ||
| const stringUnionSelector = (obj, key, union, type) => { | ||
| if (!(key in obj)) | ||
| return undefined; | ||
| const value = obj[key].toUpperCase(); | ||
| if (!Object.values(union).includes(value)) { | ||
| throw new TypeError(`Cannot load ${type} '${key}'. Expected one of ${Object.values(union)}, got '${obj[key]}'.`); | ||
| } | ||
| return value; | ||
| }; | ||
| const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION"; | ||
| const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation"; | ||
| const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS = { | ||
| environmentVariableSelector: (env) => stringUnionSelector(env, ENV_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.ENV), | ||
| configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.CONFIG), | ||
| default: DEFAULT_REQUEST_CHECKSUM_CALCULATION, | ||
| }; | ||
| const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION"; | ||
| const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation"; | ||
| const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS = { | ||
| environmentVariableSelector: (env) => stringUnionSelector(env, ENV_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.ENV), | ||
| configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.CONFIG), | ||
| default: DEFAULT_RESPONSE_CHECKSUM_VALIDATION, | ||
| }; | ||
| const getChecksumAlgorithmForRequest = (input, { requestChecksumRequired, requestAlgorithmMember, requestChecksumCalculation }) => { | ||
| if (!requestAlgorithmMember) { | ||
| return requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired | ||
| ? DEFAULT_CHECKSUM_ALGORITHM | ||
| : undefined; | ||
| } | ||
| if (!input[requestAlgorithmMember]) { | ||
| return undefined; | ||
| } | ||
| const checksumAlgorithm = input[requestAlgorithmMember]; | ||
| return checksumAlgorithm; | ||
| }; | ||
| const getChecksumLocationName = (algorithm) => algorithm === ChecksumAlgorithm.MD5 ? "content-md5" : `x-amz-checksum-${algorithm.toLowerCase()}`; | ||
| const hasHeader = (header, headers) => { | ||
| const soughtHeader = header.toLowerCase(); | ||
| for (const headerName of Object.keys(headers)) { | ||
| if (soughtHeader === headerName.toLowerCase()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; | ||
| const hasHeaderWithPrefix = (headerPrefix, headers) => { | ||
| const soughtHeaderPrefix = headerPrefix.toLowerCase(); | ||
| for (const headerName of Object.keys(headers)) { | ||
| if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; | ||
| const isStreaming = (body) => body !== undefined && typeof body !== "string" && !ArrayBuffer.isView(body) && !isArrayBuffer(body); | ||
| const CLIENT_SUPPORTED_ALGORITHMS = [ | ||
| ChecksumAlgorithm.CRC32, | ||
| ChecksumAlgorithm.CRC32C, | ||
| ChecksumAlgorithm.CRC64NVME, | ||
| ChecksumAlgorithm.SHA1, | ||
| ChecksumAlgorithm.SHA256, | ||
| ]; | ||
| const PRIORITY_ORDER_ALGORITHMS = [ | ||
| ChecksumAlgorithm.SHA256, | ||
| ChecksumAlgorithm.SHA1, | ||
| ChecksumAlgorithm.CRC32, | ||
| ChecksumAlgorithm.CRC32C, | ||
| ChecksumAlgorithm.CRC64NVME, | ||
| ]; | ||
| const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => { | ||
| const { checksumAlgorithms = {} } = config; | ||
| switch (checksumAlgorithm) { | ||
| case ChecksumAlgorithm.MD5: | ||
| return checksumAlgorithms?.MD5 ?? config.md5; | ||
| case ChecksumAlgorithm.CRC32: | ||
| return checksumAlgorithms?.CRC32 ?? Crc32; | ||
| case ChecksumAlgorithm.CRC32C: | ||
| return checksumAlgorithms?.CRC32C ?? Crc32c; | ||
| case ChecksumAlgorithm.CRC64NVME: | ||
| return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme; | ||
| case ChecksumAlgorithm.SHA1: | ||
| return checksumAlgorithms?.SHA1 ?? config.sha1; | ||
| case ChecksumAlgorithm.SHA256: | ||
| return checksumAlgorithms?.SHA256 ?? config.sha256; | ||
| default: | ||
| if (checksumAlgorithms?.[checksumAlgorithm]) { | ||
| return checksumAlgorithms[checksumAlgorithm]; | ||
| } | ||
| throw new Error(`The checksum algorithm "${checksumAlgorithm}" is not supported by the client.` + | ||
| ` Select one of ${CLIENT_SUPPORTED_ALGORITHMS}, or provide an implementation to ` + | ||
| ` the client constructor checksums field.`); | ||
| } | ||
| }; | ||
| const stringHasher = (checksumAlgorithmFn, body) => { | ||
| const hash = new checksumAlgorithmFn(); | ||
| hash.update(toUint8Array(body || "")); | ||
| return hash.digest(); | ||
| }; | ||
| const flexibleChecksumsMiddlewareOptions = { | ||
| name: "flexibleChecksumsMiddleware", | ||
| step: "build", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| if (!HttpRequest.isInstance(args.request)) { | ||
| return next(args); | ||
| } | ||
| if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) { | ||
| return next(args); | ||
| } | ||
| const { request, input } = args; | ||
| const { body: requestBody, headers } = request; | ||
| const { base64Encoder, streamHasher } = config; | ||
| const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; | ||
| const requestChecksumCalculation = await config.requestChecksumCalculation(); | ||
| const requestAlgorithmMemberName = requestAlgorithmMember?.name; | ||
| const requestAlgorithmMemberHttpHeader = requestAlgorithmMember?.httpHeader; | ||
| if (requestAlgorithmMemberName && !input[requestAlgorithmMemberName]) { | ||
| if (requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired) { | ||
| input[requestAlgorithmMemberName] = DEFAULT_CHECKSUM_ALGORITHM; | ||
| if (requestAlgorithmMemberHttpHeader) { | ||
| headers[requestAlgorithmMemberHttpHeader] = DEFAULT_CHECKSUM_ALGORITHM; | ||
| } | ||
| } | ||
| } | ||
| const checksumAlgorithm = getChecksumAlgorithmForRequest(input, { | ||
| requestChecksumRequired, | ||
| requestAlgorithmMember: requestAlgorithmMember?.name, | ||
| requestChecksumCalculation, | ||
| }); | ||
| let updatedBody = requestBody; | ||
| let updatedHeaders = headers; | ||
| if (checksumAlgorithm) { | ||
| switch (checksumAlgorithm) { | ||
| case ChecksumAlgorithm.CRC32: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32", "U"); | ||
| break; | ||
| case ChecksumAlgorithm.CRC32C: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V"); | ||
| break; | ||
| case ChecksumAlgorithm.CRC64NVME: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W"); | ||
| break; | ||
| case ChecksumAlgorithm.SHA1: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X"); | ||
| break; | ||
| case ChecksumAlgorithm.SHA256: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA256", "Y"); | ||
| break; | ||
| } | ||
| const checksumLocationName = getChecksumLocationName(checksumAlgorithm); | ||
| const checksumAlgorithmFn = selectChecksumAlgorithmFunction(checksumAlgorithm, config); | ||
| if (isStreaming(requestBody)) { | ||
| const { getAwsChunkedEncodingStream, bodyLengthChecker } = config; | ||
| updatedBody = getAwsChunkedEncodingStream(typeof config.requestStreamBufferSize === "number" && config.requestStreamBufferSize >= 8 * 1024 | ||
| ? createBufferedReadable(requestBody, config.requestStreamBufferSize, context.logger) | ||
| : requestBody, { | ||
| base64Encoder, | ||
| bodyLengthChecker, | ||
| checksumLocationName, | ||
| checksumAlgorithmFn, | ||
| streamHasher, | ||
| }); | ||
| updatedHeaders = { | ||
| ...headers, | ||
| "content-encoding": headers["content-encoding"] | ||
| ? `${headers["content-encoding"]},aws-chunked` | ||
| : "aws-chunked", | ||
| "transfer-encoding": "chunked", | ||
| "x-amz-decoded-content-length": headers["content-length"], | ||
| "x-amz-content-sha256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER", | ||
| "x-amz-trailer": checksumLocationName, | ||
| }; | ||
| delete updatedHeaders["content-length"]; | ||
| } | ||
| else if (!hasHeader(checksumLocationName, headers)) { | ||
| const rawChecksum = await stringHasher(checksumAlgorithmFn, requestBody); | ||
| updatedHeaders = { | ||
| ...headers, | ||
| [checksumLocationName]: base64Encoder(rawChecksum), | ||
| }; | ||
| } | ||
| } | ||
| try { | ||
| const result = await next({ | ||
| ...args, | ||
| request: { | ||
| ...request, | ||
| headers: updatedHeaders, | ||
| body: updatedBody, | ||
| }, | ||
| }); | ||
| return result; | ||
| } | ||
| catch (e) { | ||
| if (e instanceof Error && e.name === "InvalidChunkSizeError") { | ||
| try { | ||
| if (!e.message.endsWith(".")) { | ||
| e.message += "."; | ||
| } | ||
| e.message += | ||
| " Set [requestStreamBufferSize=number e.g. 65_536] in client constructor to instruct AWS SDK to buffer your input stream."; | ||
| } | ||
| catch (ignored) { | ||
| } | ||
| } | ||
| throw e; | ||
| } | ||
| }; | ||
| const flexibleChecksumsInputMiddlewareOptions = { | ||
| name: "flexibleChecksumsInputMiddleware", | ||
| toMiddleware: "serializerMiddleware", | ||
| relation: "before", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| const flexibleChecksumsInputMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| const input = args.input; | ||
| const { requestValidationModeMember } = middlewareConfig; | ||
| const requestChecksumCalculation = await config.requestChecksumCalculation(); | ||
| const responseChecksumValidation = await config.responseChecksumValidation(); | ||
| switch (requestChecksumCalculation) { | ||
| case RequestChecksumCalculation.WHEN_REQUIRED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED", "a"); | ||
| break; | ||
| case RequestChecksumCalculation.WHEN_SUPPORTED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED", "Z"); | ||
| break; | ||
| } | ||
| switch (responseChecksumValidation) { | ||
| case ResponseChecksumValidation.WHEN_REQUIRED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED", "c"); | ||
| break; | ||
| case ResponseChecksumValidation.WHEN_SUPPORTED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED", "b"); | ||
| break; | ||
| } | ||
| if (requestValidationModeMember && !input[requestValidationModeMember]) { | ||
| if (responseChecksumValidation === ResponseChecksumValidation.WHEN_SUPPORTED) { | ||
| input[requestValidationModeMember] = "ENABLED"; | ||
| } | ||
| } | ||
| return next(args); | ||
| }; | ||
| const getChecksumAlgorithmListForResponse = (responseAlgorithms = []) => { | ||
| const validChecksumAlgorithms = []; | ||
| let i = PRIORITY_ORDER_ALGORITHMS.length; | ||
| for (const algorithm of responseAlgorithms) { | ||
| const priority = PRIORITY_ORDER_ALGORITHMS.indexOf(algorithm); | ||
| if (priority !== -1) { | ||
| validChecksumAlgorithms[priority] = algorithm; | ||
| } | ||
| else { | ||
| validChecksumAlgorithms[i++] = algorithm; | ||
| } | ||
| } | ||
| return validChecksumAlgorithms.filter(Boolean); | ||
| }; | ||
| const isChecksumWithPartNumber = (checksum) => { | ||
| const lastHyphenIndex = checksum.lastIndexOf("-"); | ||
| if (lastHyphenIndex !== -1) { | ||
| const numberPart = checksum.slice(lastHyphenIndex + 1); | ||
| if (!numberPart.startsWith("0")) { | ||
| const number = parseInt(numberPart, 10); | ||
| if (!isNaN(number) && number >= 1 && number <= 10000) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| }; | ||
| const getChecksum = async (body, { checksumAlgorithmFn, base64Encoder }) => base64Encoder(await stringHasher(checksumAlgorithmFn, body)); | ||
| const validateChecksumFromResponse = async (response, { config, responseAlgorithms, logger }) => { | ||
| const checksumAlgorithms = getChecksumAlgorithmListForResponse(responseAlgorithms); | ||
| const { body: responseBody, headers: responseHeaders } = response; | ||
| for (const algorithm of checksumAlgorithms) { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| const checksumFromResponse = responseHeaders[responseHeader]; | ||
| if (checksumFromResponse) { | ||
| let checksumAlgorithmFn; | ||
| try { | ||
| checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config); | ||
| } | ||
| catch (error) { | ||
| if (algorithm === ChecksumAlgorithm.CRC64NVME) { | ||
| logger?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`); | ||
| continue; | ||
| } | ||
| throw error; | ||
| } | ||
| const { base64Encoder } = config; | ||
| if (isStreaming(responseBody)) { | ||
| response.body = createChecksumStream({ | ||
| expectedChecksum: checksumFromResponse, | ||
| checksumSourceLocation: responseHeader, | ||
| checksum: new checksumAlgorithmFn(), | ||
| source: responseBody, | ||
| base64Encoder, | ||
| }); | ||
| return; | ||
| } | ||
| const checksum = await getChecksum(responseBody, { checksumAlgorithmFn, base64Encoder }); | ||
| if (checksum === checksumFromResponse) { | ||
| break; | ||
| } | ||
| throw new Error(`Checksum mismatch: expected "${checksum}" but received "${checksumFromResponse}"` + | ||
| ` in response header "${responseHeader}".`); | ||
| } | ||
| } | ||
| }; | ||
| const flexibleChecksumsResponseMiddlewareOptions = { | ||
| name: "flexibleChecksumsResponseMiddleware", | ||
| toMiddleware: "deserializerMiddleware", | ||
| relation: "after", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| const flexibleChecksumsResponseMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| if (!HttpRequest.isInstance(args.request)) { | ||
| return next(args); | ||
| } | ||
| const input = args.input; | ||
| const result = await next(args); | ||
| const response = result.response; | ||
| const { requestValidationModeMember, responseAlgorithms } = middlewareConfig; | ||
| if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") { | ||
| const { clientName, commandName } = context; | ||
| const customChecksumAlgorithms = Object.keys(config.checksumAlgorithms ?? {}).filter((algorithm) => { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| return response.headers[responseHeader] !== undefined; | ||
| }); | ||
| const algoList = getChecksumAlgorithmListForResponse([ | ||
| ...(responseAlgorithms ?? []), | ||
| ...customChecksumAlgorithms, | ||
| ]); | ||
| const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" && | ||
| commandName === "GetObjectCommand" && | ||
| algoList.every((algorithm) => { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| const checksumFromResponse = response.headers[responseHeader]; | ||
| return !checksumFromResponse || isChecksumWithPartNumber(checksumFromResponse); | ||
| }); | ||
| if (isS3WholeObjectMultipartGetResponseChecksum) { | ||
| return result; | ||
| } | ||
| await validateChecksumFromResponse(response, { | ||
| config, | ||
| responseAlgorithms: algoList, | ||
| logger: context.logger, | ||
| }); | ||
| } | ||
| return result; | ||
| }; | ||
| const getFlexibleChecksumsPlugin = (config, middlewareConfig) => ({ | ||
| applyToStack: (clientStack) => { | ||
| clientStack.add(flexibleChecksumsMiddleware(config, middlewareConfig), flexibleChecksumsMiddlewareOptions); | ||
| clientStack.addRelativeTo(flexibleChecksumsInputMiddleware(config, middlewareConfig), flexibleChecksumsInputMiddlewareOptions); | ||
| clientStack.addRelativeTo(flexibleChecksumsResponseMiddleware(config, middlewareConfig), flexibleChecksumsResponseMiddlewareOptions); | ||
| }, | ||
| }); | ||
| const resolveFlexibleChecksumsConfig = (input) => { | ||
| const { requestChecksumCalculation, responseChecksumValidation, requestStreamBufferSize } = input; | ||
| return Object.assign(input, { | ||
| requestChecksumCalculation: normalizeProvider(requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION), | ||
| responseChecksumValidation: normalizeProvider(responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION), | ||
| requestStreamBufferSize: Number(requestStreamBufferSize ?? 0), | ||
| checksumAlgorithms: input.checksumAlgorithms ?? {}, | ||
| }); | ||
| }; | ||
| exports.CONFIG_REQUEST_CHECKSUM_CALCULATION = CONFIG_REQUEST_CHECKSUM_CALCULATION; | ||
| exports.CONFIG_RESPONSE_CHECKSUM_VALIDATION = CONFIG_RESPONSE_CHECKSUM_VALIDATION; | ||
| exports.ChecksumAlgorithm = ChecksumAlgorithm; | ||
| exports.ChecksumLocation = ChecksumLocation; | ||
| exports.DEFAULT_CHECKSUM_ALGORITHM = DEFAULT_CHECKSUM_ALGORITHM; | ||
| exports.DEFAULT_REQUEST_CHECKSUM_CALCULATION = DEFAULT_REQUEST_CHECKSUM_CALCULATION; | ||
| exports.DEFAULT_RESPONSE_CHECKSUM_VALIDATION = DEFAULT_RESPONSE_CHECKSUM_VALIDATION; | ||
| exports.ENV_REQUEST_CHECKSUM_CALCULATION = ENV_REQUEST_CHECKSUM_CALCULATION; | ||
| exports.ENV_RESPONSE_CHECKSUM_VALIDATION = ENV_RESPONSE_CHECKSUM_VALIDATION; | ||
| exports.NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS = NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS; | ||
| exports.NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS = NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS; | ||
| exports.RequestChecksumCalculation = RequestChecksumCalculation; | ||
| exports.ResponseChecksumValidation = ResponseChecksumValidation; | ||
| exports.flexibleChecksumsMiddleware = flexibleChecksumsMiddleware; | ||
| exports.flexibleChecksumsMiddlewareOptions = flexibleChecksumsMiddlewareOptions; | ||
| exports.getFlexibleChecksumsPlugin = getFlexibleChecksumsPlugin; | ||
| exports.resolveFlexibleChecksumsConfig = resolveFlexibleChecksumsConfig; |
| const { Md5, Md5Js, Md5Node } = require("@smithy/core/checksum"); | ||
| exports.Md5 = Md5; | ||
| exports.Md5Js = Md5Js; | ||
| exports.Md5Node = Md5Node; |
| const { toUint8Array, concatBytes } = require("@smithy/core/serde"); | ||
| const { createHmac, createHash } = require("node:crypto"); | ||
| const { Sha256, Sha256Js, Sha256Node } = require("@smithy/core/checksum"); | ||
| exports.Sha256 = Sha256; | ||
| exports.Sha256Js = Sha256Js; | ||
| exports.Sha256Node = Sha256Node; | ||
| const BLOCK = 64; | ||
| const DIGEST_LENGTH = 20; | ||
| const INIT = new Int32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]); | ||
| const K = new Int32Array([0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]); | ||
| class Sha1Js { | ||
| digestLength = DIGEST_LENGTH; | ||
| state = Int32Array.from(INIT); | ||
| w; | ||
| buffer = new Uint8Array(BLOCK); | ||
| bufferLength = 0; | ||
| bytesHashed = 0; | ||
| finished = false; | ||
| inner; | ||
| outer; | ||
| constructor(secret) { | ||
| if (secret) { | ||
| const key = Sha1Js.normalizeKey(secret); | ||
| this.inner = new Sha1Js(); | ||
| this.outer = new Sha1Js(); | ||
| const pad = new Uint8Array(BLOCK * 2); | ||
| for (let i = 0; i < BLOCK; ++i) { | ||
| pad[i] = 0x36 ^ key[i]; | ||
| pad[i + BLOCK] = 0x5c ^ key[i]; | ||
| } | ||
| this.inner.update(pad.subarray(0, BLOCK)); | ||
| this.outer.update(pad.subarray(BLOCK)); | ||
| } | ||
| } | ||
| update(data) { | ||
| if (this.finished) { | ||
| throw new Error("Attempted to update an already finished HMAC."); | ||
| } | ||
| if (this.inner) { | ||
| this.inner.update(data); | ||
| return; | ||
| } | ||
| let pos = 0; | ||
| let { length } = data; | ||
| this.bytesHashed += length; | ||
| if (this.bufferLength > 0) { | ||
| while (length > 0 && this.bufferLength < BLOCK) { | ||
| this.buffer[this.bufferLength++] = data[pos++]; | ||
| --length; | ||
| } | ||
| if (this.bufferLength === BLOCK) { | ||
| this.hashBuffer(this.buffer, 0); | ||
| this.bufferLength = 0; | ||
| } | ||
| } | ||
| while (length >= BLOCK) { | ||
| this.hashBuffer(data, pos); | ||
| pos += BLOCK; | ||
| length -= BLOCK; | ||
| } | ||
| while (length > 0) { | ||
| this.buffer[this.bufferLength++] = data[pos++]; | ||
| --length; | ||
| } | ||
| } | ||
| async digest() { | ||
| if (this.inner && this.outer) { | ||
| if (this.finished) { | ||
| throw new Error("Attempted to digest an already finished HMAC."); | ||
| } | ||
| this.finished = true; | ||
| const innerDigest = this.inner.digestSync(); | ||
| this.outer.update(innerDigest); | ||
| return this.outer.digestSync(); | ||
| } | ||
| return this.digestSync(); | ||
| } | ||
| reset() { | ||
| this.state = Int32Array.from(INIT); | ||
| this.buffer = new Uint8Array(BLOCK); | ||
| this.bufferLength = 0; | ||
| this.bytesHashed = 0; | ||
| } | ||
| digestSync() { | ||
| const state = this.state.slice(); | ||
| const buffer = this.buffer.slice(); | ||
| let bufferLength = this.bufferLength; | ||
| const bitsHi = (this.bytesHashed / 0x20000000) | 0; | ||
| const bitsLo = this.bytesHashed << 3; | ||
| buffer[bufferLength++] = 0x80; | ||
| if (bufferLength > BLOCK - 8) { | ||
| for (let i = bufferLength; i < BLOCK; ++i) { | ||
| buffer[i] = 0; | ||
| } | ||
| this.hashBufferWith(state, buffer, 0); | ||
| bufferLength = 0; | ||
| } | ||
| for (let i = bufferLength; i < BLOCK - 8; ++i) { | ||
| buffer[i] = 0; | ||
| } | ||
| const v = new DataView(buffer.buffer, buffer.byteOffset, BLOCK); | ||
| v.setUint32(BLOCK - 8, bitsHi, false); | ||
| v.setUint32(BLOCK - 4, bitsLo, false); | ||
| this.hashBufferWith(state, buffer, 0); | ||
| const out = new Uint8Array(DIGEST_LENGTH); | ||
| out[0] = (state[0] >>> 24) & 0xff; | ||
| out[1] = (state[0] >>> 16) & 0xff; | ||
| out[2] = (state[0] >>> 8) & 0xff; | ||
| out[3] = state[0] & 0xff; | ||
| out[4] = (state[1] >>> 24) & 0xff; | ||
| out[5] = (state[1] >>> 16) & 0xff; | ||
| out[6] = (state[1] >>> 8) & 0xff; | ||
| out[7] = state[1] & 0xff; | ||
| out[8] = (state[2] >>> 24) & 0xff; | ||
| out[9] = (state[2] >>> 16) & 0xff; | ||
| out[10] = (state[2] >>> 8) & 0xff; | ||
| out[11] = state[2] & 0xff; | ||
| out[12] = (state[3] >>> 24) & 0xff; | ||
| out[13] = (state[3] >>> 16) & 0xff; | ||
| out[14] = (state[3] >>> 8) & 0xff; | ||
| out[15] = state[3] & 0xff; | ||
| out[16] = (state[4] >>> 24) & 0xff; | ||
| out[17] = (state[4] >>> 16) & 0xff; | ||
| out[18] = (state[4] >>> 8) & 0xff; | ||
| out[19] = state[4] & 0xff; | ||
| return out; | ||
| } | ||
| static normalizeKey(secret) { | ||
| const key = toUint8Array(secret); | ||
| if (key.byteLength > BLOCK) { | ||
| const h = new Sha1Js(); | ||
| h.update(key); | ||
| const digest = h.digestSync(); | ||
| const padded = new Uint8Array(BLOCK); | ||
| padded.set(digest); | ||
| return padded; | ||
| } | ||
| const padded = new Uint8Array(BLOCK); | ||
| padded.set(key); | ||
| return padded; | ||
| } | ||
| hashBuffer(data, offset) { | ||
| this.hashBufferWith(this.state, data, offset); | ||
| } | ||
| hashBufferWith(state, data, offset) { | ||
| const w = (this.w ??= new Int32Array(80)); | ||
| let s0 = state[0], s1 = state[1], s2 = state[2], s3 = state[3], s4 = state[4]; | ||
| for (let t = 0; t < 16; ++t) { | ||
| w[t] = | ||
| ((data[offset + t * 4] & 0xff) << 24) | | ||
| ((data[offset + t * 4 + 1] & 0xff) << 16) | | ||
| ((data[offset + t * 4 + 2] & 0xff) << 8) | | ||
| (data[offset + t * 4 + 3] & 0xff); | ||
| } | ||
| for (let t = 16; t < 80; ++t) { | ||
| const x = w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]; | ||
| w[t] = (x << 1) | (x >>> 31); | ||
| } | ||
| for (let t = 0; t < 80; ++t) { | ||
| const r = t < 20 ? 0 : t < 40 ? 1 : t < 60 ? 2 : 3; | ||
| const temp = (((((s0 << 5) | (s0 >>> 27)) + | ||
| (r === 0 ? (s1 & s2) ^ (~s1 & s3) : r === 2 ? (s1 & s2) ^ (s1 & s3) ^ (s2 & s3) : s1 ^ s2 ^ s3)) | | ||
| 0) + | ||
| ((s4 + ((K[r] + w[t]) | 0)) | 0)) | | ||
| 0; | ||
| s4 = s3; | ||
| s3 = s2; | ||
| s2 = (s1 << 30) | (s1 >>> 2); | ||
| s1 = s0; | ||
| s0 = temp; | ||
| } | ||
| state[0] = (state[0] + s0) | 0; | ||
| state[1] = (state[1] + s1) | 0; | ||
| state[2] = (state[2] + s2) | 0; | ||
| state[3] = (state[3] + s3) | 0; | ||
| state[4] = (state[4] + s4) | 0; | ||
| } | ||
| } | ||
| const hasNativeCrypto = (() => { | ||
| try { | ||
| createHash("sha1"); | ||
| return true; | ||
| } | ||
| catch { | ||
| return false; | ||
| } | ||
| })(); | ||
| const Sha1Node = hasNativeCrypto ? buildNativeClass() : Sha1Js; | ||
| function buildNativeClass() { | ||
| return class Sha1Node { | ||
| digestLength = 20; | ||
| secret; | ||
| hash; | ||
| isHmac; | ||
| finished = false; | ||
| constructor(secret) { | ||
| this.secret = secret; | ||
| this.isHmac = !!secret; | ||
| this.hash = this.createHash(); | ||
| } | ||
| update(data) { | ||
| if (this.finished) { | ||
| throw new Error("Attempted to update an already finished hash."); | ||
| } | ||
| this.hash.update(data); | ||
| } | ||
| async digest() { | ||
| let buf; | ||
| if (this.isHmac) { | ||
| this.finished = true; | ||
| buf = this.hash.digest(); | ||
| } | ||
| else { | ||
| buf = this.hash.copy().digest(); | ||
| } | ||
| return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength); | ||
| } | ||
| reset() { | ||
| this.hash = this.createHash(); | ||
| this.finished = false; | ||
| } | ||
| createHash() { | ||
| return this.secret ? createHmac("sha1", toBuffer(this.secret)) : createHash("sha1"); | ||
| } | ||
| }; | ||
| } | ||
| function toBuffer(data) { | ||
| if (typeof data === "string") { | ||
| return data; | ||
| } | ||
| if (ArrayBuffer.isView(data)) { | ||
| return Buffer.from(data.buffer, data.byteOffset, data.byteLength); | ||
| } | ||
| return Buffer.from(data); | ||
| } | ||
| const { digest, sign, importKey } = globalThis?.crypto?.subtle ?? {}; | ||
| const subtle = typeof digest === "function" && typeof sign === "function" && typeof importKey === "function" | ||
| ? globalThis.crypto.subtle | ||
| : undefined; | ||
| const MAX_PENDING_BYTES = 8 * 1024 * 1024; | ||
| class Sha1WebCrypto { | ||
| digestLength = 20; | ||
| secret; | ||
| pending = []; | ||
| pendingBytes = 0; | ||
| fallback; | ||
| finished = false; | ||
| constructor(secret) { | ||
| if (secret) { | ||
| this.secret = toUint8Array(secret); | ||
| } | ||
| } | ||
| update(data) { | ||
| if (this.finished) { | ||
| throw new Error("Attempted to update an already finished HMAC."); | ||
| } | ||
| if (this.fallback) { | ||
| this.fallback.update(data); | ||
| return; | ||
| } | ||
| this.pending.push(data.slice()); | ||
| this.pendingBytes += data.byteLength; | ||
| if (this.pendingBytes >= MAX_PENDING_BYTES) { | ||
| this.switchToFallback(); | ||
| } | ||
| } | ||
| async digest() { | ||
| if (this.fallback) { | ||
| return this.fallback.digest(); | ||
| } | ||
| if (this.secret && this.finished) { | ||
| throw new Error("Attempted to digest an already finished HMAC."); | ||
| } | ||
| const data = concatBytes(this.pending); | ||
| if (subtle) { | ||
| if (this.secret) { | ||
| this.finished = true; | ||
| const key = await subtle.importKey("raw", this.secret, { name: "HMAC", hash: "SHA-1" }, false, ["sign"]); | ||
| const sig = await subtle.sign("HMAC", key, data); | ||
| return new Uint8Array(sig); | ||
| } | ||
| const hash = await subtle.digest("SHA-1", data); | ||
| return new Uint8Array(hash); | ||
| } | ||
| const sha1 = new Sha1Js(this.secret); | ||
| sha1.update(data); | ||
| return sha1.digest(); | ||
| } | ||
| reset() { | ||
| this.pending = []; | ||
| this.pendingBytes = 0; | ||
| this.fallback = undefined; | ||
| this.finished = false; | ||
| } | ||
| switchToFallback() { | ||
| const sha1Js = new Sha1Js(this.secret); | ||
| for (const chunk of this.pending) { | ||
| sha1Js.update(chunk); | ||
| } | ||
| this.fallback = sha1Js; | ||
| this.pending = []; | ||
| this.pendingBytes = 0; | ||
| } | ||
| } | ||
| exports.Sha1 = Sha1Node; | ||
| exports.Sha1Js = Sha1Js; | ||
| exports.Sha1Node = Sha1Node; | ||
| exports.Sha1WebCrypto = Sha1WebCrypto; |
| const T = new Uint32Array(256); | ||
| for (let i = 0; i < 256; ++i) { | ||
| let c = i; | ||
| for (let j = 0; j < 8; ++j) { | ||
| c = c & 1 ? 0x82f63b78 ^ (c >>> 1) : c >>> 1; | ||
| } | ||
| T[i] = c >>> 0; | ||
| } | ||
| export class Crc32cJs { | ||
| digestLength = 4; | ||
| crc = 0xffff_ffff; | ||
| update(data) { | ||
| let crc = this.crc; | ||
| for (let i = 0; i < data.length; ++i) { | ||
| crc = (crc >>> 8) ^ T[(crc ^ data[i]) & 0xff]; | ||
| } | ||
| this.crc = crc; | ||
| } | ||
| async digest() { | ||
| const value = (this.crc ^ 0xffff_ffff) >>> 0; | ||
| const out = new Uint8Array(4); | ||
| out[0] = value >>> 24; | ||
| out[1] = (value >>> 16) & 0xff; | ||
| out[2] = (value >>> 8) & 0xff; | ||
| out[3] = value & 0xff; | ||
| return out; | ||
| } | ||
| reset() { | ||
| this.crc = 0xffff_ffff; | ||
| } | ||
| } |
| import { Crc32cJs } from "./Crc32cJs"; | ||
| export const Crc32cNode = Crc32cJs; |
| export const crc64NvmeCrtContainer = { | ||
| CrtCrc64Nvme: null, | ||
| }; |
| import { crc64NvmeCrtContainer } from "./crc64-nvme-crt-container"; | ||
| import { Crc64NvmeJs } from "./Crc64NvmeJs"; | ||
| export class Crc64Nvme { | ||
| impl; | ||
| constructor() { | ||
| const Crt = crc64NvmeCrtContainer.CrtCrc64Nvme; | ||
| this.impl = Crt ? new Crt() : new Crc64NvmeJs(); | ||
| } | ||
| update(data) { | ||
| this.impl.update(data); | ||
| } | ||
| async digest() { | ||
| return this.impl.digest(); | ||
| } | ||
| reset() { | ||
| this.impl.reset(); | ||
| } | ||
| } |
| const generateCRC64NVMETable = () => { | ||
| const sliceLength = 8; | ||
| const tables = new Array(sliceLength); | ||
| for (let slice = 0; slice < sliceLength; slice++) { | ||
| const table = new Array(512); | ||
| for (let i = 0; i < 256; i++) { | ||
| let crc = BigInt(i); | ||
| for (let j = 0; j < 8 * (slice + 1); j++) { | ||
| if (crc & 1n) { | ||
| crc = (crc >> 1n) ^ 0x9a6c9329ac4bc9b5n; | ||
| } | ||
| else { | ||
| crc = crc >> 1n; | ||
| } | ||
| } | ||
| table[i * 2] = Number((crc >> 32n) & 0xffffffffn); | ||
| table[i * 2 + 1] = Number(crc & 0xffffffffn); | ||
| } | ||
| tables[slice] = new Uint32Array(table); | ||
| } | ||
| return tables; | ||
| }; | ||
| let CRC64_NVME_REVERSED_TABLE; | ||
| let t0, t1, t2, t3; | ||
| let t4, t5, t6, t7; | ||
| const ensureTablesInitialized = () => { | ||
| if (!CRC64_NVME_REVERSED_TABLE) { | ||
| CRC64_NVME_REVERSED_TABLE = generateCRC64NVMETable(); | ||
| [t0, t1, t2, t3, t4, t5, t6, t7] = CRC64_NVME_REVERSED_TABLE; | ||
| } | ||
| }; | ||
| export class Crc64NvmeJs { | ||
| c1 = 0; | ||
| c2 = 0; | ||
| constructor() { | ||
| ensureTablesInitialized(); | ||
| this.reset(); | ||
| } | ||
| update(data) { | ||
| const len = data.length; | ||
| let i = 0; | ||
| let crc1 = this.c1; | ||
| let crc2 = this.c2; | ||
| while (i + 8 <= len) { | ||
| const idx0 = ((crc2 ^ data[i++]) & 255) << 1; | ||
| const idx1 = (((crc2 >>> 8) ^ data[i++]) & 255) << 1; | ||
| const idx2 = (((crc2 >>> 16) ^ data[i++]) & 255) << 1; | ||
| const idx3 = (((crc2 >>> 24) ^ data[i++]) & 255) << 1; | ||
| const idx4 = ((crc1 ^ data[i++]) & 255) << 1; | ||
| const idx5 = (((crc1 >>> 8) ^ data[i++]) & 255) << 1; | ||
| const idx6 = (((crc1 >>> 16) ^ data[i++]) & 255) << 1; | ||
| const idx7 = (((crc1 >>> 24) ^ data[i++]) & 255) << 1; | ||
| crc1 = t7[idx0] ^ t6[idx1] ^ t5[idx2] ^ t4[idx3] ^ t3[idx4] ^ t2[idx5] ^ t1[idx6] ^ t0[idx7]; | ||
| crc2 = | ||
| t7[idx0 + 1] ^ | ||
| t6[idx1 + 1] ^ | ||
| t5[idx2 + 1] ^ | ||
| t4[idx3 + 1] ^ | ||
| t3[idx4 + 1] ^ | ||
| t2[idx5 + 1] ^ | ||
| t1[idx6 + 1] ^ | ||
| t0[idx7 + 1]; | ||
| } | ||
| while (i < len) { | ||
| const idx = ((crc2 ^ data[i]) & 255) << 1; | ||
| crc2 = ((crc2 >>> 8) | ((crc1 & 255) << 24)) >>> 0; | ||
| crc1 = (crc1 >>> 8) ^ t0[idx]; | ||
| crc2 ^= t0[idx + 1]; | ||
| ++i; | ||
| } | ||
| this.c1 = crc1; | ||
| this.c2 = crc2; | ||
| } | ||
| async digest() { | ||
| const c1 = this.c1 ^ 4294967295; | ||
| const c2 = this.c2 ^ 4294967295; | ||
| return new Uint8Array([ | ||
| c1 >>> 24, | ||
| (c1 >>> 16) & 255, | ||
| (c1 >>> 8) & 255, | ||
| c1 & 255, | ||
| c2 >>> 24, | ||
| (c2 >>> 16) & 255, | ||
| (c2 >>> 8) & 255, | ||
| c2 & 255, | ||
| ]); | ||
| } | ||
| reset() { | ||
| this.c1 = 4294967295; | ||
| this.c2 = 4294967295; | ||
| } | ||
| } |
| const no = Symbol.for("node-only"); | ||
| export { Crc32cJs, Crc32cJs as Crc32c } from "./crc32c/Crc32cJs"; | ||
| export const Crc32cNode = no; | ||
| export { Crc64NvmeJs, Crc64NvmeJs as Crc64Nvme } from "./crc64-nvme/Crc64NvmeJs"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { Crc32, Crc32Js, Crc32Node } from "@smithy/core/checksum"; |
| export { Crc32cJs } from "./crc32c/Crc32cJs"; | ||
| export { Crc32cNode, Crc32cNode as Crc32c } from "./crc32c/Crc32cNode"; | ||
| export { Crc64Nvme } from "./crc64-nvme/Crc64Nvme"; | ||
| export { Crc64NvmeJs } from "./crc64-nvme/Crc64NvmeJs"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { Crc32, Crc32Js, Crc32Node } from "@smithy/core/checksum"; |
| export const RequestChecksumCalculation = { | ||
| WHEN_SUPPORTED: "WHEN_SUPPORTED", | ||
| WHEN_REQUIRED: "WHEN_REQUIRED", | ||
| }; | ||
| export const DEFAULT_REQUEST_CHECKSUM_CALCULATION = RequestChecksumCalculation.WHEN_SUPPORTED; | ||
| export const ResponseChecksumValidation = { | ||
| WHEN_SUPPORTED: "WHEN_SUPPORTED", | ||
| WHEN_REQUIRED: "WHEN_REQUIRED", | ||
| }; | ||
| export const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.WHEN_SUPPORTED; | ||
| export var ChecksumAlgorithm; | ||
| (function (ChecksumAlgorithm) { | ||
| ChecksumAlgorithm["MD5"] = "MD5"; | ||
| ChecksumAlgorithm["CRC32"] = "CRC32"; | ||
| ChecksumAlgorithm["CRC32C"] = "CRC32C"; | ||
| ChecksumAlgorithm["CRC64NVME"] = "CRC64NVME"; | ||
| ChecksumAlgorithm["SHA1"] = "SHA1"; | ||
| ChecksumAlgorithm["SHA256"] = "SHA256"; | ||
| })(ChecksumAlgorithm || (ChecksumAlgorithm = {})); | ||
| export var ChecksumLocation; | ||
| (function (ChecksumLocation) { | ||
| ChecksumLocation["HEADER"] = "header"; | ||
| ChecksumLocation["TRAILER"] = "trailer"; | ||
| })(ChecksumLocation || (ChecksumLocation = {})); | ||
| export const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; |
| import { setFeature } from "@aws-sdk/core/client"; | ||
| import { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; | ||
| export const flexibleChecksumsInputMiddlewareOptions = { | ||
| name: "flexibleChecksumsInputMiddleware", | ||
| toMiddleware: "serializerMiddleware", | ||
| relation: "before", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| export const flexibleChecksumsInputMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| const input = args.input; | ||
| const { requestValidationModeMember } = middlewareConfig; | ||
| const requestChecksumCalculation = await config.requestChecksumCalculation(); | ||
| const responseChecksumValidation = await config.responseChecksumValidation(); | ||
| switch (requestChecksumCalculation) { | ||
| case RequestChecksumCalculation.WHEN_REQUIRED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED", "a"); | ||
| break; | ||
| case RequestChecksumCalculation.WHEN_SUPPORTED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED", "Z"); | ||
| break; | ||
| } | ||
| switch (responseChecksumValidation) { | ||
| case ResponseChecksumValidation.WHEN_REQUIRED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED", "c"); | ||
| break; | ||
| case ResponseChecksumValidation.WHEN_SUPPORTED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED", "b"); | ||
| break; | ||
| } | ||
| if (requestValidationModeMember && !input[requestValidationModeMember]) { | ||
| if (responseChecksumValidation === ResponseChecksumValidation.WHEN_SUPPORTED) { | ||
| input[requestValidationModeMember] = "ENABLED"; | ||
| } | ||
| } | ||
| return next(args); | ||
| }; |
| import { setFeature } from "@aws-sdk/core/client"; | ||
| import { HttpRequest } from "@smithy/core/protocols"; | ||
| import { createBufferedReadable } from "@smithy/core/serde"; | ||
| import { ChecksumAlgorithm, DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation } from "./constants"; | ||
| import { getChecksumAlgorithmForRequest } from "./getChecksumAlgorithmForRequest"; | ||
| import { getChecksumLocationName } from "./getChecksumLocationName"; | ||
| import { hasHeader } from "./hasHeader"; | ||
| import { hasHeaderWithPrefix } from "./hasHeaderWithPrefix"; | ||
| import { isStreaming } from "./isStreaming"; | ||
| import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction"; | ||
| import { stringHasher } from "./stringHasher"; | ||
| export const flexibleChecksumsMiddlewareOptions = { | ||
| name: "flexibleChecksumsMiddleware", | ||
| step: "build", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| export const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| if (!HttpRequest.isInstance(args.request)) { | ||
| return next(args); | ||
| } | ||
| if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) { | ||
| return next(args); | ||
| } | ||
| const { request, input } = args; | ||
| const { body: requestBody, headers } = request; | ||
| const { base64Encoder, streamHasher } = config; | ||
| const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; | ||
| const requestChecksumCalculation = await config.requestChecksumCalculation(); | ||
| const requestAlgorithmMemberName = requestAlgorithmMember?.name; | ||
| const requestAlgorithmMemberHttpHeader = requestAlgorithmMember?.httpHeader; | ||
| if (requestAlgorithmMemberName && !input[requestAlgorithmMemberName]) { | ||
| if (requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired) { | ||
| input[requestAlgorithmMemberName] = DEFAULT_CHECKSUM_ALGORITHM; | ||
| if (requestAlgorithmMemberHttpHeader) { | ||
| headers[requestAlgorithmMemberHttpHeader] = DEFAULT_CHECKSUM_ALGORITHM; | ||
| } | ||
| } | ||
| } | ||
| const checksumAlgorithm = getChecksumAlgorithmForRequest(input, { | ||
| requestChecksumRequired, | ||
| requestAlgorithmMember: requestAlgorithmMember?.name, | ||
| requestChecksumCalculation, | ||
| }); | ||
| let updatedBody = requestBody; | ||
| let updatedHeaders = headers; | ||
| if (checksumAlgorithm) { | ||
| switch (checksumAlgorithm) { | ||
| case ChecksumAlgorithm.CRC32: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32", "U"); | ||
| break; | ||
| case ChecksumAlgorithm.CRC32C: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V"); | ||
| break; | ||
| case ChecksumAlgorithm.CRC64NVME: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W"); | ||
| break; | ||
| case ChecksumAlgorithm.SHA1: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X"); | ||
| break; | ||
| case ChecksumAlgorithm.SHA256: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA256", "Y"); | ||
| break; | ||
| } | ||
| const checksumLocationName = getChecksumLocationName(checksumAlgorithm); | ||
| const checksumAlgorithmFn = selectChecksumAlgorithmFunction(checksumAlgorithm, config); | ||
| if (isStreaming(requestBody)) { | ||
| const { getAwsChunkedEncodingStream, bodyLengthChecker } = config; | ||
| updatedBody = getAwsChunkedEncodingStream(typeof config.requestStreamBufferSize === "number" && config.requestStreamBufferSize >= 8 * 1024 | ||
| ? createBufferedReadable(requestBody, config.requestStreamBufferSize, context.logger) | ||
| : requestBody, { | ||
| base64Encoder, | ||
| bodyLengthChecker, | ||
| checksumLocationName, | ||
| checksumAlgorithmFn, | ||
| streamHasher, | ||
| }); | ||
| updatedHeaders = { | ||
| ...headers, | ||
| "content-encoding": headers["content-encoding"] | ||
| ? `${headers["content-encoding"]},aws-chunked` | ||
| : "aws-chunked", | ||
| "transfer-encoding": "chunked", | ||
| "x-amz-decoded-content-length": headers["content-length"], | ||
| "x-amz-content-sha256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER", | ||
| "x-amz-trailer": checksumLocationName, | ||
| }; | ||
| delete updatedHeaders["content-length"]; | ||
| } | ||
| else if (!hasHeader(checksumLocationName, headers)) { | ||
| const rawChecksum = await stringHasher(checksumAlgorithmFn, requestBody); | ||
| updatedHeaders = { | ||
| ...headers, | ||
| [checksumLocationName]: base64Encoder(rawChecksum), | ||
| }; | ||
| } | ||
| } | ||
| try { | ||
| const result = await next({ | ||
| ...args, | ||
| request: { | ||
| ...request, | ||
| headers: updatedHeaders, | ||
| body: updatedBody, | ||
| }, | ||
| }); | ||
| return result; | ||
| } | ||
| catch (e) { | ||
| if (e instanceof Error && e.name === "InvalidChunkSizeError") { | ||
| try { | ||
| if (!e.message.endsWith(".")) { | ||
| e.message += "."; | ||
| } | ||
| e.message += | ||
| " Set [requestStreamBufferSize=number e.g. 65_536] in client constructor to instruct AWS SDK to buffer your input stream."; | ||
| } | ||
| catch (ignored) { | ||
| } | ||
| } | ||
| throw e; | ||
| } | ||
| }; |
| import { HttpRequest } from "@smithy/core/protocols"; | ||
| import { getChecksumAlgorithmListForResponse } from "./getChecksumAlgorithmListForResponse"; | ||
| import { getChecksumLocationName } from "./getChecksumLocationName"; | ||
| import { isChecksumWithPartNumber } from "./isChecksumWithPartNumber"; | ||
| import { validateChecksumFromResponse } from "./validateChecksumFromResponse"; | ||
| export const flexibleChecksumsResponseMiddlewareOptions = { | ||
| name: "flexibleChecksumsResponseMiddleware", | ||
| toMiddleware: "deserializerMiddleware", | ||
| relation: "after", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| export const flexibleChecksumsResponseMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| if (!HttpRequest.isInstance(args.request)) { | ||
| return next(args); | ||
| } | ||
| const input = args.input; | ||
| const result = await next(args); | ||
| const response = result.response; | ||
| const { requestValidationModeMember, responseAlgorithms } = middlewareConfig; | ||
| if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") { | ||
| const { clientName, commandName } = context; | ||
| const customChecksumAlgorithms = Object.keys(config.checksumAlgorithms ?? {}).filter((algorithm) => { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| return response.headers[responseHeader] !== undefined; | ||
| }); | ||
| const algoList = getChecksumAlgorithmListForResponse([ | ||
| ...(responseAlgorithms ?? []), | ||
| ...customChecksumAlgorithms, | ||
| ]); | ||
| const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" && | ||
| commandName === "GetObjectCommand" && | ||
| algoList.every((algorithm) => { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| const checksumFromResponse = response.headers[responseHeader]; | ||
| return !checksumFromResponse || isChecksumWithPartNumber(checksumFromResponse); | ||
| }); | ||
| if (isS3WholeObjectMultipartGetResponseChecksum) { | ||
| return result; | ||
| } | ||
| await validateChecksumFromResponse(response, { | ||
| config, | ||
| responseAlgorithms: algoList, | ||
| logger: context.logger, | ||
| }); | ||
| } | ||
| return result; | ||
| }; |
| import { stringHasher } from "./stringHasher"; | ||
| export const getChecksum = async (body, { checksumAlgorithmFn, base64Encoder }) => base64Encoder(await stringHasher(checksumAlgorithmFn, body)); |
| import { DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation } from "./constants"; | ||
| export const getChecksumAlgorithmForRequest = (input, { requestChecksumRequired, requestAlgorithmMember, requestChecksumCalculation }) => { | ||
| if (!requestAlgorithmMember) { | ||
| return requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired | ||
| ? DEFAULT_CHECKSUM_ALGORITHM | ||
| : undefined; | ||
| } | ||
| if (!input[requestAlgorithmMember]) { | ||
| return undefined; | ||
| } | ||
| const checksumAlgorithm = input[requestAlgorithmMember]; | ||
| return checksumAlgorithm; | ||
| }; |
| import { PRIORITY_ORDER_ALGORITHMS } from "./types"; | ||
| export const getChecksumAlgorithmListForResponse = (responseAlgorithms = []) => { | ||
| const validChecksumAlgorithms = []; | ||
| let i = PRIORITY_ORDER_ALGORITHMS.length; | ||
| for (const algorithm of responseAlgorithms) { | ||
| const priority = PRIORITY_ORDER_ALGORITHMS.indexOf(algorithm); | ||
| if (priority !== -1) { | ||
| validChecksumAlgorithms[priority] = algorithm; | ||
| } | ||
| else { | ||
| validChecksumAlgorithms[i++] = algorithm; | ||
| } | ||
| } | ||
| return validChecksumAlgorithms.filter(Boolean); | ||
| }; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export const getChecksumLocationName = (algorithm) => algorithm === ChecksumAlgorithm.MD5 ? "content-md5" : `x-amz-checksum-${algorithm.toLowerCase()}`; |
| import { flexibleChecksumsInputMiddleware, flexibleChecksumsInputMiddlewareOptions, } from "./flexibleChecksumsInputMiddleware"; | ||
| import { flexibleChecksumsMiddleware, flexibleChecksumsMiddlewareOptions } from "./flexibleChecksumsMiddleware"; | ||
| import { flexibleChecksumsResponseMiddleware, flexibleChecksumsResponseMiddlewareOptions, } from "./flexibleChecksumsResponseMiddleware"; | ||
| export const getFlexibleChecksumsPlugin = (config, middlewareConfig) => ({ | ||
| applyToStack: (clientStack) => { | ||
| clientStack.add(flexibleChecksumsMiddleware(config, middlewareConfig), flexibleChecksumsMiddlewareOptions); | ||
| clientStack.addRelativeTo(flexibleChecksumsInputMiddleware(config, middlewareConfig), flexibleChecksumsInputMiddlewareOptions); | ||
| clientStack.addRelativeTo(flexibleChecksumsResponseMiddleware(config, middlewareConfig), flexibleChecksumsResponseMiddlewareOptions); | ||
| }, | ||
| }); |
| export const hasHeader = (header, headers) => { | ||
| const soughtHeader = header.toLowerCase(); | ||
| for (const headerName of Object.keys(headers)) { | ||
| if (soughtHeader === headerName.toLowerCase()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; |
| export const hasHeaderWithPrefix = (headerPrefix, headers) => { | ||
| const soughtHeaderPrefix = headerPrefix.toLowerCase(); | ||
| for (const headerName of Object.keys(headers)) { | ||
| if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; |
| export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, } from "./NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS"; | ||
| export { ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, } from "./NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS"; | ||
| export { RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, } from "./constants"; | ||
| export { flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware } from "./flexibleChecksumsMiddleware"; | ||
| export { getFlexibleChecksumsPlugin } from "./getFlexibleChecksumsPlugin"; | ||
| export { resolveFlexibleChecksumsConfig } from "./resolveFlexibleChecksumsConfig"; |
| export const isChecksumWithPartNumber = (checksum) => { | ||
| const lastHyphenIndex = checksum.lastIndexOf("-"); | ||
| if (lastHyphenIndex !== -1) { | ||
| const numberPart = checksum.slice(lastHyphenIndex + 1); | ||
| if (!numberPart.startsWith("0")) { | ||
| const number = parseInt(numberPart, 10); | ||
| if (!isNaN(number) && number >= 1 && number <= 10000) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| }; |
| import { isArrayBuffer } from "@smithy/core/serde"; | ||
| export const isStreaming = (body) => body !== undefined && typeof body !== "string" && !ArrayBuffer.isView(body) && !isArrayBuffer(body); |
| import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation } from "./constants"; | ||
| import { SelectorType, stringUnionSelector } from "./stringUnionSelector"; | ||
| export const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION"; | ||
| export const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation"; | ||
| export const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS = { | ||
| environmentVariableSelector: (env) => stringUnionSelector(env, ENV_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.ENV), | ||
| configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.CONFIG), | ||
| default: DEFAULT_REQUEST_CHECKSUM_CALCULATION, | ||
| }; |
| import { DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation } from "./constants"; | ||
| import { SelectorType, stringUnionSelector } from "./stringUnionSelector"; | ||
| export const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION"; | ||
| export const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation"; | ||
| export const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS = { | ||
| environmentVariableSelector: (env) => stringUnionSelector(env, ENV_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.ENV), | ||
| configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.CONFIG), | ||
| default: DEFAULT_RESPONSE_CHECKSUM_VALIDATION, | ||
| }; |
| import { normalizeProvider } from "@smithy/core/client"; | ||
| import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION } from "./constants"; | ||
| export const resolveFlexibleChecksumsConfig = (input) => { | ||
| const { requestChecksumCalculation, responseChecksumValidation, requestStreamBufferSize } = input; | ||
| return Object.assign(input, { | ||
| requestChecksumCalculation: normalizeProvider(requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION), | ||
| responseChecksumValidation: normalizeProvider(responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION), | ||
| requestStreamBufferSize: Number(requestStreamBufferSize ?? 0), | ||
| checksumAlgorithms: input.checksumAlgorithms ?? {}, | ||
| }); | ||
| }; |
| import { Crc32, Crc32c, Crc64Nvme } from "@aws-sdk/checksums/crc"; | ||
| import { ChecksumAlgorithm } from "./constants"; | ||
| import { CLIENT_SUPPORTED_ALGORITHMS } from "./types"; | ||
| export const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => { | ||
| const { checksumAlgorithms = {} } = config; | ||
| switch (checksumAlgorithm) { | ||
| case ChecksumAlgorithm.MD5: | ||
| return checksumAlgorithms?.MD5 ?? config.md5; | ||
| case ChecksumAlgorithm.CRC32: | ||
| return checksumAlgorithms?.CRC32 ?? Crc32; | ||
| case ChecksumAlgorithm.CRC32C: | ||
| return checksumAlgorithms?.CRC32C ?? Crc32c; | ||
| case ChecksumAlgorithm.CRC64NVME: | ||
| return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme; | ||
| case ChecksumAlgorithm.SHA1: | ||
| return checksumAlgorithms?.SHA1 ?? config.sha1; | ||
| case ChecksumAlgorithm.SHA256: | ||
| return checksumAlgorithms?.SHA256 ?? config.sha256; | ||
| default: | ||
| if (checksumAlgorithms?.[checksumAlgorithm]) { | ||
| return checksumAlgorithms[checksumAlgorithm]; | ||
| } | ||
| throw new Error(`The checksum algorithm "${checksumAlgorithm}" is not supported by the client.` + | ||
| ` Select one of ${CLIENT_SUPPORTED_ALGORITHMS}, or provide an implementation to ` + | ||
| ` the client constructor checksums field.`); | ||
| } | ||
| }; |
| import { toUint8Array } from "@smithy/core/serde"; | ||
| export const stringHasher = (checksumAlgorithmFn, body) => { | ||
| const hash = new checksumAlgorithmFn(); | ||
| hash.update(toUint8Array(body || "")); | ||
| return hash.digest(); | ||
| }; |
| export var SelectorType; | ||
| (function (SelectorType) { | ||
| SelectorType["ENV"] = "env"; | ||
| SelectorType["CONFIG"] = "shared config entry"; | ||
| })(SelectorType || (SelectorType = {})); | ||
| export const stringUnionSelector = (obj, key, union, type) => { | ||
| if (!(key in obj)) | ||
| return undefined; | ||
| const value = obj[key].toUpperCase(); | ||
| if (!Object.values(union).includes(value)) { | ||
| throw new TypeError(`Cannot load ${type} '${key}'. Expected one of ${Object.values(union)}, got '${obj[key]}'.`); | ||
| } | ||
| return value; | ||
| }; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export const CLIENT_SUPPORTED_ALGORITHMS = [ | ||
| ChecksumAlgorithm.CRC32, | ||
| ChecksumAlgorithm.CRC32C, | ||
| ChecksumAlgorithm.CRC64NVME, | ||
| ChecksumAlgorithm.SHA1, | ||
| ChecksumAlgorithm.SHA256, | ||
| ]; | ||
| export const PRIORITY_ORDER_ALGORITHMS = [ | ||
| ChecksumAlgorithm.SHA256, | ||
| ChecksumAlgorithm.SHA1, | ||
| ChecksumAlgorithm.CRC32, | ||
| ChecksumAlgorithm.CRC32C, | ||
| ChecksumAlgorithm.CRC64NVME, | ||
| ]; |
| import { createChecksumStream } from "@smithy/core/serde"; | ||
| import { ChecksumAlgorithm } from "./constants"; | ||
| import { getChecksum } from "./getChecksum"; | ||
| import { getChecksumAlgorithmListForResponse } from "./getChecksumAlgorithmListForResponse"; | ||
| import { getChecksumLocationName } from "./getChecksumLocationName"; | ||
| import { isStreaming } from "./isStreaming"; | ||
| import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction"; | ||
| export const validateChecksumFromResponse = async (response, { config, responseAlgorithms, logger }) => { | ||
| const checksumAlgorithms = getChecksumAlgorithmListForResponse(responseAlgorithms); | ||
| const { body: responseBody, headers: responseHeaders } = response; | ||
| for (const algorithm of checksumAlgorithms) { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| const checksumFromResponse = responseHeaders[responseHeader]; | ||
| if (checksumFromResponse) { | ||
| let checksumAlgorithmFn; | ||
| try { | ||
| checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config); | ||
| } | ||
| catch (error) { | ||
| if (algorithm === ChecksumAlgorithm.CRC64NVME) { | ||
| logger?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`); | ||
| continue; | ||
| } | ||
| throw error; | ||
| } | ||
| const { base64Encoder } = config; | ||
| if (isStreaming(responseBody)) { | ||
| response.body = createChecksumStream({ | ||
| expectedChecksum: checksumFromResponse, | ||
| checksumSourceLocation: responseHeader, | ||
| checksum: new checksumAlgorithmFn(), | ||
| source: responseBody, | ||
| base64Encoder, | ||
| }); | ||
| return; | ||
| } | ||
| const checksum = await getChecksum(responseBody, { checksumAlgorithmFn, base64Encoder }); | ||
| if (checksum === checksumFromResponse) { | ||
| break; | ||
| } | ||
| throw new Error(`Checksum mismatch: expected "${checksum}" but received "${checksumFromResponse}"` + | ||
| ` in response header "${responseHeader}".`); | ||
| } | ||
| } | ||
| }; |
| export { Md5, Md5Js, Md5Node } from "@smithy/core/checksum"; |
| const no = Symbol.for("node-only"); | ||
| export { Sha1Js, Sha1Js as Sha1 } from "./sha1/Sha1Js"; | ||
| export const Sha1Node = no; | ||
| export { Sha256, Sha256Js, Sha256Node, Sha256WebCrypto } from "@smithy/core/checksum"; |
| export { Sha1Js } from "./sha1/Sha1Js"; | ||
| export { Sha1Node, Sha1Node as Sha1 } from "./sha1/Sha1Node"; | ||
| export { Sha1WebCrypto } from "./sha1/Sha1WebCrypto"; | ||
| export { Sha256, Sha256Js, Sha256Node } from "@smithy/core/checksum"; |
| import { toUint8Array } from "@smithy/core/serde"; | ||
| const BLOCK = 64; | ||
| const DIGEST_LENGTH = 20; | ||
| const INIT = new Int32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]); | ||
| const K = new Int32Array([0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]); | ||
| export class Sha1Js { | ||
| digestLength = DIGEST_LENGTH; | ||
| state = Int32Array.from(INIT); | ||
| w; | ||
| buffer = new Uint8Array(BLOCK); | ||
| bufferLength = 0; | ||
| bytesHashed = 0; | ||
| finished = false; | ||
| inner; | ||
| outer; | ||
| constructor(secret) { | ||
| if (secret) { | ||
| const key = Sha1Js.normalizeKey(secret); | ||
| this.inner = new Sha1Js(); | ||
| this.outer = new Sha1Js(); | ||
| const pad = new Uint8Array(BLOCK * 2); | ||
| for (let i = 0; i < BLOCK; ++i) { | ||
| pad[i] = 0x36 ^ key[i]; | ||
| pad[i + BLOCK] = 0x5c ^ key[i]; | ||
| } | ||
| this.inner.update(pad.subarray(0, BLOCK)); | ||
| this.outer.update(pad.subarray(BLOCK)); | ||
| } | ||
| } | ||
| update(data) { | ||
| if (this.finished) { | ||
| throw new Error("Attempted to update an already finished HMAC."); | ||
| } | ||
| if (this.inner) { | ||
| this.inner.update(data); | ||
| return; | ||
| } | ||
| let pos = 0; | ||
| let { length } = data; | ||
| this.bytesHashed += length; | ||
| if (this.bufferLength > 0) { | ||
| while (length > 0 && this.bufferLength < BLOCK) { | ||
| this.buffer[this.bufferLength++] = data[pos++]; | ||
| --length; | ||
| } | ||
| if (this.bufferLength === BLOCK) { | ||
| this.hashBuffer(this.buffer, 0); | ||
| this.bufferLength = 0; | ||
| } | ||
| } | ||
| while (length >= BLOCK) { | ||
| this.hashBuffer(data, pos); | ||
| pos += BLOCK; | ||
| length -= BLOCK; | ||
| } | ||
| while (length > 0) { | ||
| this.buffer[this.bufferLength++] = data[pos++]; | ||
| --length; | ||
| } | ||
| } | ||
| async digest() { | ||
| if (this.inner && this.outer) { | ||
| if (this.finished) { | ||
| throw new Error("Attempted to digest an already finished HMAC."); | ||
| } | ||
| this.finished = true; | ||
| const innerDigest = this.inner.digestSync(); | ||
| this.outer.update(innerDigest); | ||
| return this.outer.digestSync(); | ||
| } | ||
| return this.digestSync(); | ||
| } | ||
| reset() { | ||
| this.state = Int32Array.from(INIT); | ||
| this.buffer = new Uint8Array(BLOCK); | ||
| this.bufferLength = 0; | ||
| this.bytesHashed = 0; | ||
| } | ||
| digestSync() { | ||
| const state = this.state.slice(); | ||
| const buffer = this.buffer.slice(); | ||
| let bufferLength = this.bufferLength; | ||
| const bitsHi = (this.bytesHashed / 0x20000000) | 0; | ||
| const bitsLo = this.bytesHashed << 3; | ||
| buffer[bufferLength++] = 0x80; | ||
| if (bufferLength > BLOCK - 8) { | ||
| for (let i = bufferLength; i < BLOCK; ++i) { | ||
| buffer[i] = 0; | ||
| } | ||
| this.hashBufferWith(state, buffer, 0); | ||
| bufferLength = 0; | ||
| } | ||
| for (let i = bufferLength; i < BLOCK - 8; ++i) { | ||
| buffer[i] = 0; | ||
| } | ||
| const v = new DataView(buffer.buffer, buffer.byteOffset, BLOCK); | ||
| v.setUint32(BLOCK - 8, bitsHi, false); | ||
| v.setUint32(BLOCK - 4, bitsLo, false); | ||
| this.hashBufferWith(state, buffer, 0); | ||
| const out = new Uint8Array(DIGEST_LENGTH); | ||
| out[0] = (state[0] >>> 24) & 0xff; | ||
| out[1] = (state[0] >>> 16) & 0xff; | ||
| out[2] = (state[0] >>> 8) & 0xff; | ||
| out[3] = state[0] & 0xff; | ||
| out[4] = (state[1] >>> 24) & 0xff; | ||
| out[5] = (state[1] >>> 16) & 0xff; | ||
| out[6] = (state[1] >>> 8) & 0xff; | ||
| out[7] = state[1] & 0xff; | ||
| out[8] = (state[2] >>> 24) & 0xff; | ||
| out[9] = (state[2] >>> 16) & 0xff; | ||
| out[10] = (state[2] >>> 8) & 0xff; | ||
| out[11] = state[2] & 0xff; | ||
| out[12] = (state[3] >>> 24) & 0xff; | ||
| out[13] = (state[3] >>> 16) & 0xff; | ||
| out[14] = (state[3] >>> 8) & 0xff; | ||
| out[15] = state[3] & 0xff; | ||
| out[16] = (state[4] >>> 24) & 0xff; | ||
| out[17] = (state[4] >>> 16) & 0xff; | ||
| out[18] = (state[4] >>> 8) & 0xff; | ||
| out[19] = state[4] & 0xff; | ||
| return out; | ||
| } | ||
| static normalizeKey(secret) { | ||
| const key = toUint8Array(secret); | ||
| if (key.byteLength > BLOCK) { | ||
| const h = new Sha1Js(); | ||
| h.update(key); | ||
| const digest = h.digestSync(); | ||
| const padded = new Uint8Array(BLOCK); | ||
| padded.set(digest); | ||
| return padded; | ||
| } | ||
| const padded = new Uint8Array(BLOCK); | ||
| padded.set(key); | ||
| return padded; | ||
| } | ||
| hashBuffer(data, offset) { | ||
| this.hashBufferWith(this.state, data, offset); | ||
| } | ||
| hashBufferWith(state, data, offset) { | ||
| const w = (this.w ??= new Int32Array(80)); | ||
| let s0 = state[0], s1 = state[1], s2 = state[2], s3 = state[3], s4 = state[4]; | ||
| for (let t = 0; t < 16; ++t) { | ||
| w[t] = | ||
| ((data[offset + t * 4] & 0xff) << 24) | | ||
| ((data[offset + t * 4 + 1] & 0xff) << 16) | | ||
| ((data[offset + t * 4 + 2] & 0xff) << 8) | | ||
| (data[offset + t * 4 + 3] & 0xff); | ||
| } | ||
| for (let t = 16; t < 80; ++t) { | ||
| const x = w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]; | ||
| w[t] = (x << 1) | (x >>> 31); | ||
| } | ||
| for (let t = 0; t < 80; ++t) { | ||
| const r = t < 20 ? 0 : t < 40 ? 1 : t < 60 ? 2 : 3; | ||
| const temp = (((((s0 << 5) | (s0 >>> 27)) + | ||
| (r === 0 ? (s1 & s2) ^ (~s1 & s3) : r === 2 ? (s1 & s2) ^ (s1 & s3) ^ (s2 & s3) : s1 ^ s2 ^ s3)) | | ||
| 0) + | ||
| ((s4 + ((K[r] + w[t]) | 0)) | 0)) | | ||
| 0; | ||
| s4 = s3; | ||
| s3 = s2; | ||
| s2 = (s1 << 30) | (s1 >>> 2); | ||
| s1 = s0; | ||
| s0 = temp; | ||
| } | ||
| state[0] = (state[0] + s0) | 0; | ||
| state[1] = (state[1] + s1) | 0; | ||
| state[2] = (state[2] + s2) | 0; | ||
| state[3] = (state[3] + s3) | 0; | ||
| state[4] = (state[4] + s4) | 0; | ||
| } | ||
| } |
| import { createHash, createHmac } from "node:crypto"; | ||
| import { Sha1Js } from "./Sha1Js"; | ||
| const hasNativeCrypto = (() => { | ||
| try { | ||
| createHash("sha1"); | ||
| return true; | ||
| } | ||
| catch { | ||
| return false; | ||
| } | ||
| })(); | ||
| export const Sha1Node = hasNativeCrypto ? buildNativeClass() : Sha1Js; | ||
| function buildNativeClass() { | ||
| return class Sha1Node { | ||
| digestLength = 20; | ||
| secret; | ||
| hash; | ||
| isHmac; | ||
| finished = false; | ||
| constructor(secret) { | ||
| this.secret = secret; | ||
| this.isHmac = !!secret; | ||
| this.hash = this.createHash(); | ||
| } | ||
| update(data) { | ||
| if (this.finished) { | ||
| throw new Error("Attempted to update an already finished hash."); | ||
| } | ||
| this.hash.update(data); | ||
| } | ||
| async digest() { | ||
| let buf; | ||
| if (this.isHmac) { | ||
| this.finished = true; | ||
| buf = this.hash.digest(); | ||
| } | ||
| else { | ||
| buf = this.hash.copy().digest(); | ||
| } | ||
| return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength); | ||
| } | ||
| reset() { | ||
| this.hash = this.createHash(); | ||
| this.finished = false; | ||
| } | ||
| createHash() { | ||
| return this.secret ? createHmac("sha1", toBuffer(this.secret)) : createHash("sha1"); | ||
| } | ||
| }; | ||
| } | ||
| function toBuffer(data) { | ||
| if (typeof data === "string") { | ||
| return data; | ||
| } | ||
| if (ArrayBuffer.isView(data)) { | ||
| return Buffer.from(data.buffer, data.byteOffset, data.byteLength); | ||
| } | ||
| return Buffer.from(data); | ||
| } |
| import { concatBytes, toUint8Array } from "@smithy/core/serde"; | ||
| import { Sha1Js } from "./Sha1Js"; | ||
| const { digest, sign, importKey } = globalThis?.crypto?.subtle ?? {}; | ||
| const subtle = typeof digest === "function" && typeof sign === "function" && typeof importKey === "function" | ||
| ? globalThis.crypto.subtle | ||
| : undefined; | ||
| const MAX_PENDING_BYTES = 8 * 1024 * 1024; | ||
| export class Sha1WebCrypto { | ||
| digestLength = 20; | ||
| secret; | ||
| pending = []; | ||
| pendingBytes = 0; | ||
| fallback; | ||
| finished = false; | ||
| constructor(secret) { | ||
| if (secret) { | ||
| this.secret = toUint8Array(secret); | ||
| } | ||
| } | ||
| update(data) { | ||
| if (this.finished) { | ||
| throw new Error("Attempted to update an already finished HMAC."); | ||
| } | ||
| if (this.fallback) { | ||
| this.fallback.update(data); | ||
| return; | ||
| } | ||
| this.pending.push(data.slice()); | ||
| this.pendingBytes += data.byteLength; | ||
| if (this.pendingBytes >= MAX_PENDING_BYTES) { | ||
| this.switchToFallback(); | ||
| } | ||
| } | ||
| async digest() { | ||
| if (this.fallback) { | ||
| return this.fallback.digest(); | ||
| } | ||
| if (this.secret && this.finished) { | ||
| throw new Error("Attempted to digest an already finished HMAC."); | ||
| } | ||
| const data = concatBytes(this.pending); | ||
| if (subtle) { | ||
| if (this.secret) { | ||
| this.finished = true; | ||
| const key = await subtle.importKey("raw", this.secret, { name: "HMAC", hash: "SHA-1" }, false, ["sign"]); | ||
| const sig = await subtle.sign("HMAC", key, data); | ||
| return new Uint8Array(sig); | ||
| } | ||
| const hash = await subtle.digest("SHA-1", data); | ||
| return new Uint8Array(hash); | ||
| } | ||
| const sha1 = new Sha1Js(this.secret); | ||
| sha1.update(data); | ||
| return sha1.digest(); | ||
| } | ||
| reset() { | ||
| this.pending = []; | ||
| this.pendingBytes = 0; | ||
| this.fallback = undefined; | ||
| this.finished = false; | ||
| } | ||
| switchToFallback() { | ||
| const sha1Js = new Sha1Js(this.secret); | ||
| for (const chunk of this.pending) { | ||
| sha1Js.update(chunk); | ||
| } | ||
| this.fallback = sha1Js; | ||
| this.pending = []; | ||
| this.pendingBytes = 0; | ||
| } | ||
| } |
| import type { Checksum } from "@smithy/types"; | ||
| /** | ||
| * Pure JS CRC-32C using the Castagnoli polynomial. | ||
| * Non-destructive digest — safe to call digest() multiple times. | ||
| * @public | ||
| */ | ||
| export declare class Crc32cJs implements Checksum { | ||
| readonly digestLength = 4; | ||
| private crc; | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } |
| import type { Checksum } from "@smithy/types"; | ||
| /** | ||
| * CRC-32C (Castagnoli). No native Node.js implementation exists, | ||
| * so this is equivalent to the pure JS version. | ||
| * @public | ||
| */ | ||
| export interface Crc32cNode extends Checksum { | ||
| readonly digestLength: 4; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare const Crc32cNode: new () => Crc32cNode; |
| import type { ChecksumConstructor } from "@smithy/types"; | ||
| /** | ||
| * \@aws-sdk/crc64-nvme-crt will install the constructor in this | ||
| * container if it is installed. | ||
| * | ||
| * This avoids a runtime-require being interpreted statically by bundlers. | ||
| * @internal | ||
| */ | ||
| export declare const crc64NvmeCrtContainer: { | ||
| CrtCrc64Nvme: null | ChecksumConstructor; | ||
| }; |
| import type { Checksum } from "@smithy/types"; | ||
| /** | ||
| * CRC-64/NVME checksum. Uses the CRT native implementation if loaded, | ||
| * otherwise falls back to the pure JS implementation. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const checksum = new Crc64Nvme(); | ||
| * checksum.update(new Uint8Array([1, 2, 3])); | ||
| * const result = await checksum.digest(); | ||
| * ``` | ||
| * | ||
| * @public | ||
| */ | ||
| export declare class Crc64Nvme implements Checksum { | ||
| private impl; | ||
| constructor(); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } |
| import type { Checksum } from "@smithy/types"; | ||
| /** | ||
| * Pure JS CRC-64/NVME implementation using the NVMe polynomial (0x9a6c9329ac4bc9b5). | ||
| * Uses an 8-slice lookup table for efficient computation. | ||
| * @public | ||
| */ | ||
| export declare class Crc64NvmeJs implements Checksum { | ||
| private c1; | ||
| private c2; | ||
| constructor(); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } |
| export { Crc32cJs, Crc32cJs as Crc32c } from "./crc32c/Crc32cJs"; | ||
| export declare const Crc32cNode: symbol; | ||
| export { Crc64NvmeJs, Crc64NvmeJs as Crc64Nvme } from "./crc64-nvme/Crc64NvmeJs"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { Crc32, Crc32Js, Crc32Node } from "@smithy/core/checksum"; |
| export { Crc32cJs } from "./crc32c/Crc32cJs"; | ||
| export { Crc32cNode, Crc32cNode as Crc32c } from "./crc32c/Crc32cNode"; | ||
| export { Crc64Nvme } from "./crc64-nvme/Crc64Nvme"; | ||
| export { Crc64NvmeJs } from "./crc64-nvme/Crc64NvmeJs"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { Crc32, Crc32Js, Crc32Node } from "@smithy/core/checksum"; |
| import type { BodyLengthCalculator, ChecksumConstructor, Encoder, GetAwsChunkedEncodingStream, HashConstructor, Provider, StreamCollector, StreamHasher } from "@smithy/types"; | ||
| import type { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; | ||
| import type { FlexibleChecksumsInputConfig } from "./resolveFlexibleChecksumsConfig"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface PreviouslyResolved { | ||
| /** | ||
| * The function that will be used to convert binary data to a base64-encoded string. | ||
| * @internal | ||
| */ | ||
| base64Encoder: Encoder; | ||
| /** | ||
| * A function that can calculate the length of a body. | ||
| */ | ||
| bodyLengthChecker: BodyLengthCalculator; | ||
| /** | ||
| * A function that returns Readable Stream which follows aws-chunked encoding stream. | ||
| */ | ||
| getAwsChunkedEncodingStream: GetAwsChunkedEncodingStream; | ||
| /** | ||
| * A constructor for a class implementing the {@link Hash} interface that computes MD5 hashes. | ||
| * @internal | ||
| */ | ||
| md5: ChecksumConstructor | HashConstructor; | ||
| /** | ||
| * Determines when a checksum will be calculated for request payloads | ||
| */ | ||
| requestChecksumCalculation: Provider<RequestChecksumCalculation>; | ||
| /** | ||
| * Determines when a checksum will be calculated for response payloads | ||
| */ | ||
| responseChecksumValidation: Provider<ResponseChecksumValidation>; | ||
| /** | ||
| * A constructor for a class implementing the {@link Hash} interface that computes SHA1 hashes. | ||
| * @internal | ||
| */ | ||
| sha1: ChecksumConstructor | HashConstructor; | ||
| /** | ||
| * A constructor for a class implementing the {@link Hash} interface that computes SHA256 hashes. | ||
| * @internal | ||
| */ | ||
| sha256: ChecksumConstructor | HashConstructor; | ||
| /** | ||
| * A function that, given a hash constructor and a stream, calculates the hash of the streamed value. | ||
| * @internal | ||
| */ | ||
| streamHasher: StreamHasher<any>; | ||
| /** | ||
| * Collects streams into buffers. | ||
| */ | ||
| streamCollector: StreamCollector; | ||
| /** | ||
| * Minimum bytes from a stream to buffer into a chunk before passing to chunked encoding. | ||
| */ | ||
| requestStreamBufferSize: number; | ||
| checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"]; | ||
| } |
| /** | ||
| * Determines when a checksum will be calculated for request payloads. | ||
| * @public | ||
| */ | ||
| export declare const RequestChecksumCalculation: { | ||
| /** | ||
| * When set, a checksum will be calculated for all request payloads of operations | ||
| * modeled with the {@link httpChecksum} trait where `requestChecksumRequired` is `true` | ||
| * AND/OR a `requestAlgorithmMember` is modeled. | ||
| * {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum} | ||
| */ | ||
| readonly WHEN_SUPPORTED: "WHEN_SUPPORTED"; | ||
| /** | ||
| * When set, a checksum will only be calculated for request payloads of operations | ||
| * modeled with the {@link httpChecksum} trait where `requestChecksumRequired` is `true` | ||
| * OR where a `requestAlgorithmMember` is modeled and the user sets it. | ||
| * {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum} | ||
| */ | ||
| readonly WHEN_REQUIRED: "WHEN_REQUIRED"; | ||
| }; | ||
| /** | ||
| * @public | ||
| */ | ||
| export type RequestChecksumCalculation = (typeof RequestChecksumCalculation)[keyof typeof RequestChecksumCalculation]; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const DEFAULT_REQUEST_CHECKSUM_CALCULATION: "WHEN_SUPPORTED"; | ||
| /** | ||
| * Determines when checksum validation will be performed on response payloads. | ||
| * @public | ||
| */ | ||
| export declare const ResponseChecksumValidation: { | ||
| /** | ||
| * When set, checksum validation MUST be performed on all response payloads of operations | ||
| * modeled with the {@link httpChecksum} trait where `responseAlgorithms` is modeled, | ||
| * except when no modeled checksum algorithms are supported by an SDK. | ||
| * {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum} | ||
| */ | ||
| readonly WHEN_SUPPORTED: "WHEN_SUPPORTED"; | ||
| /** | ||
| * When set, checksum validation MUST NOT be performed on response payloads of operations UNLESS | ||
| * the SDK supports the modeled checksum algorithms AND the user has set the `requestValidationModeMember` to `ENABLED`. | ||
| * It is currently impossible to model an operation as requiring a response checksum, | ||
| * but this setting leaves the door open for future updates. | ||
| */ | ||
| readonly WHEN_REQUIRED: "WHEN_REQUIRED"; | ||
| }; | ||
| /** | ||
| * @public | ||
| */ | ||
| export type ResponseChecksumValidation = (typeof ResponseChecksumValidation)[keyof typeof ResponseChecksumValidation]; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const DEFAULT_RESPONSE_CHECKSUM_VALIDATION: "WHEN_SUPPORTED"; | ||
| /** | ||
| * Checksum Algorithms supported by the SDK. | ||
| * @public | ||
| */ | ||
| export declare enum ChecksumAlgorithm { | ||
| /** | ||
| * @deprecated Use {@link ChecksumAlgorithm.CRC32} instead. | ||
| */ | ||
| MD5 = "MD5", | ||
| CRC32 = "CRC32", | ||
| CRC32C = "CRC32C", | ||
| CRC64NVME = "CRC64NVME", | ||
| SHA1 = "SHA1", | ||
| SHA256 = "SHA256" | ||
| } | ||
| /** | ||
| * Location when the checksum is stored in the request body. | ||
| * @internal | ||
| */ | ||
| export declare enum ChecksumLocation { | ||
| HEADER = "header", | ||
| TRAILER = "trailer" | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; |
| import type { RelativeMiddlewareOptions, SerializeMiddleware } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsInputMiddlewareConfig { | ||
| /** | ||
| * Defines a top-level operation input member used to opt-in to best-effort validation | ||
| * of a checksum returned in the HTTP response of the operation. | ||
| */ | ||
| requestValidationModeMember?: string; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const flexibleChecksumsInputMiddlewareOptions: RelativeMiddlewareOptions; | ||
| /** | ||
| * @internal | ||
| * | ||
| * The input counterpart to the flexibleChecksumsMiddleware. | ||
| */ | ||
| export declare const flexibleChecksumsInputMiddleware: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsInputMiddlewareConfig) => SerializeMiddleware<any, any>; |
| import type { BuildHandlerOptions, BuildMiddleware } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsRequestMiddlewareConfig { | ||
| /** | ||
| * Indicates an operation requires a checksum in its HTTP request. | ||
| */ | ||
| requestChecksumRequired: boolean; | ||
| /** | ||
| * Member that is used to configure request checksum behavior. | ||
| */ | ||
| requestAlgorithmMember?: { | ||
| /** | ||
| * Defines a top-level operation input member that is used to configure request checksum behavior. | ||
| */ | ||
| name: string; | ||
| /** | ||
| * The {@link httpHeader} value, if present. | ||
| * {@link https://smithy.io/2.0/spec/http-bindings.html#httpheader-trait httpHeader} | ||
| */ | ||
| httpHeader?: string; | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const flexibleChecksumsMiddlewareOptions: BuildHandlerOptions; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const flexibleChecksumsMiddleware: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsRequestMiddlewareConfig) => BuildMiddleware<any, any>; |
| import type { DeserializeMiddleware, RelativeMiddlewareOptions } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsResponseMiddlewareConfig { | ||
| /** | ||
| * Defines a top-level operation input member used to opt-in to best-effort validation | ||
| * of a checksum returned in the HTTP response of the operation. | ||
| */ | ||
| requestValidationModeMember?: string; | ||
| /** | ||
| * Defines the checksum algorithms clients SHOULD look for when validating checksums | ||
| * returned in the HTTP response. | ||
| */ | ||
| responseAlgorithms?: string[]; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const flexibleChecksumsResponseMiddlewareOptions: RelativeMiddlewareOptions; | ||
| /** | ||
| * @internal | ||
| * | ||
| * The validation counterpart to the flexibleChecksumsMiddleware. | ||
| */ | ||
| export declare const flexibleChecksumsResponseMiddleware: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsResponseMiddlewareConfig) => DeserializeMiddleware<any, any>; |
| import type { ChecksumConstructor, Encoder, HashConstructor } from "@smithy/types"; | ||
| export interface GetChecksumDigestOptions { | ||
| checksumAlgorithmFn: ChecksumConstructor | HashConstructor; | ||
| base64Encoder: Encoder; | ||
| } | ||
| export declare const getChecksum: (body: unknown, { checksumAlgorithmFn, base64Encoder }: GetChecksumDigestOptions) => Promise<string>; |
| import type { ChecksumAlgorithm } from "./constants"; | ||
| import { RequestChecksumCalculation } from "./constants"; | ||
| export interface GetChecksumAlgorithmForRequestOptions { | ||
| /** | ||
| * Indicates an operation requires a checksum in its HTTP request. | ||
| */ | ||
| requestChecksumRequired: boolean; | ||
| /** | ||
| * Defines a top-level operation input member that is used to configure request checksum behavior. | ||
| */ | ||
| requestAlgorithmMember?: string; | ||
| /** | ||
| * Determines when a checksum will be calculated for request payloads | ||
| */ | ||
| requestChecksumCalculation: RequestChecksumCalculation; | ||
| } | ||
| /** | ||
| * Returns the checksum algorithm to use for the request, along with | ||
| * the priority array of location to use to populate checksum and names | ||
| * to be used as a key at the location. | ||
| */ | ||
| export declare const getChecksumAlgorithmForRequest: (input: any, { requestChecksumRequired, requestAlgorithmMember, requestChecksumCalculation }: GetChecksumAlgorithmForRequestOptions) => ChecksumAlgorithm | string | undefined; |
| import type { ChecksumAlgorithm } from "./constants"; | ||
| /** | ||
| * Returns the priority array of algorithm to use to verify checksum and names | ||
| * to be used as a key in the response header. | ||
| */ | ||
| export declare const getChecksumAlgorithmListForResponse: (responseAlgorithms?: string[]) => ChecksumAlgorithm[]; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| /** | ||
| * Returns location (header/trailer) name to use to populate checksum in. | ||
| */ | ||
| export declare const getChecksumLocationName: (algorithm: ChecksumAlgorithm | string) => string; |
| import type { Pluggable } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| import type { FlexibleChecksumsInputMiddlewareConfig } from "./flexibleChecksumsInputMiddleware"; | ||
| import type { FlexibleChecksumsRequestMiddlewareConfig } from "./flexibleChecksumsMiddleware"; | ||
| import type { FlexibleChecksumsResponseMiddlewareConfig } from "./flexibleChecksumsResponseMiddleware"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsMiddlewareConfig extends FlexibleChecksumsRequestMiddlewareConfig, FlexibleChecksumsInputMiddlewareConfig, FlexibleChecksumsResponseMiddlewareConfig { | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const getFlexibleChecksumsPlugin: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsMiddlewareConfig) => Pluggable<any, any>; |
| import type { HeaderBag } from "@smithy/types"; | ||
| /** | ||
| * Returns true if header is present in headers. | ||
| * Comparisons are case-insensitive. | ||
| */ | ||
| export declare const hasHeader: (header: string, headers: HeaderBag) => boolean; |
| import type { HeaderBag } from "@smithy/types"; | ||
| /** | ||
| * Returns true if header with headerPrefix is present in headers. | ||
| * Comparisons are case-insensitive. | ||
| */ | ||
| export declare const hasHeaderWithPrefix: (headerPrefix: string, headers: HeaderBag) => boolean; |
| export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, } from "./NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS"; | ||
| export { ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, } from "./NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS"; | ||
| export { RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, } from "./constants"; | ||
| export type { FlexibleChecksumsRequestMiddlewareConfig } from "./flexibleChecksumsMiddleware"; | ||
| export { flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware } from "./flexibleChecksumsMiddleware"; | ||
| export type { FlexibleChecksumsMiddlewareConfig } from "./getFlexibleChecksumsPlugin"; | ||
| export { getFlexibleChecksumsPlugin } from "./getFlexibleChecksumsPlugin"; | ||
| export type { FlexibleChecksumsInputConfig, FlexibleChecksumsResolvedConfig } from "./resolveFlexibleChecksumsConfig"; | ||
| export { resolveFlexibleChecksumsConfig } from "./resolveFlexibleChecksumsConfig"; |
| export declare const isChecksumWithPartNumber: (checksum: string) => boolean; |
| /** | ||
| * Returns true if the given value is a streaming response. | ||
| */ | ||
| export declare const isStreaming: (body: unknown) => boolean; |
| import type { LoadedConfigSelectors } from "@smithy/core/config"; | ||
| import { RequestChecksumCalculation } from "./constants"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS: LoadedConfigSelectors<RequestChecksumCalculation>; |
| import type { LoadedConfigSelectors } from "@smithy/core/config"; | ||
| import { ResponseChecksumValidation } from "./constants"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS: LoadedConfigSelectors<ResponseChecksumValidation>; |
| import type { ChecksumConstructor, Provider } from "@smithy/types"; | ||
| import type { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface FlexibleChecksumsInputConfig { | ||
| /** | ||
| * Determines when a checksum will be calculated for request payloads. | ||
| */ | ||
| requestChecksumCalculation?: RequestChecksumCalculation | Provider<RequestChecksumCalculation>; | ||
| /** | ||
| * Determines when checksum validation will be performed on response payloads. | ||
| */ | ||
| responseChecksumValidation?: ResponseChecksumValidation | Provider<ResponseChecksumValidation>; | ||
| /** | ||
| * Default 0 (off). | ||
| * | ||
| * When set to a value greater than or equal to 8192, sets the minimum number | ||
| * of bytes to buffer into a chunk when processing input streams | ||
| * with chunked encoding (that is, when request checksums are enabled). | ||
| * A minimum of 8kb = 8 * 1024 is required, and 64kb or higher is recommended. | ||
| * | ||
| * See https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html. | ||
| * | ||
| * This has a slight performance penalty because it must wrap and buffer | ||
| * your input stream. | ||
| * You do not need to set this value if your stream already flows chunks | ||
| * of 8kb or greater. | ||
| */ | ||
| requestStreamBufferSize?: number | false; | ||
| /** | ||
| * Optional implementations of checksum algorithms adhering to the | ||
| * Checksum interface. | ||
| */ | ||
| checksumAlgorithms?: { | ||
| CRC32?: ChecksumConstructor; | ||
| CRC32C?: ChecksumConstructor; | ||
| CRC64NVME?: ChecksumConstructor; | ||
| SHA1?: ChecksumConstructor; | ||
| SHA256?: ChecksumConstructor; | ||
| } & { | ||
| [algorithmId: string]: ChecksumConstructor; | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsResolvedConfig { | ||
| requestChecksumCalculation: Provider<RequestChecksumCalculation>; | ||
| responseChecksumValidation: Provider<ResponseChecksumValidation>; | ||
| requestStreamBufferSize: number; | ||
| checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"]; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const resolveFlexibleChecksumsConfig: <T>(input: T & FlexibleChecksumsInputConfig) => T & FlexibleChecksumsResolvedConfig; |
| import type { ChecksumConstructor, HashConstructor } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| import { ChecksumAlgorithm } from "./constants"; | ||
| /** | ||
| * Returns the function that will compute the checksum for the given {@link ChecksumAlgorithm}. | ||
| */ | ||
| export declare const selectChecksumAlgorithmFunction: (checksumAlgorithm: ChecksumAlgorithm | string, config: PreviouslyResolved) => ChecksumConstructor | HashConstructor; |
| import type { ChecksumConstructor, HashConstructor } from "@smithy/types"; | ||
| /** | ||
| * A function that, given a hash constructor and a string, calculates the hash of the string. | ||
| */ | ||
| export declare const stringHasher: (checksumAlgorithmFn: ChecksumConstructor | HashConstructor, body: any) => Promise<Uint8Array>; |
| export declare enum SelectorType { | ||
| ENV = "env", | ||
| CONFIG = "shared config entry" | ||
| } | ||
| /** | ||
| * Returns undefined, if obj[key] is not defined. | ||
| * Returns string value, if the string is defined in obj[key] and it's uppercase matches union value. | ||
| * Throws error for all other cases. | ||
| * | ||
| * @internal | ||
| */ | ||
| export declare const stringUnionSelector: <U extends object, K extends keyof U>(obj: Record<string, string | undefined>, key: string, union: U, type: SelectorType) => U[K] | undefined; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| /** | ||
| * List of algorithms supported by client. | ||
| */ | ||
| export declare const CLIENT_SUPPORTED_ALGORITHMS: ChecksumAlgorithm[]; | ||
| /** | ||
| * Priority order for validating checksum algorithm. A faster algorithm has higher priority. | ||
| */ | ||
| export declare const PRIORITY_ORDER_ALGORITHMS: ChecksumAlgorithm[]; |
| import type { HttpResponse } from "@smithy/core/protocols"; | ||
| import type { Logger } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| export interface ValidateChecksumFromResponseOptions { | ||
| config: PreviouslyResolved; | ||
| /** | ||
| * Defines the checksum algorithms clients SHOULD look for when validating checksums | ||
| * returned in the HTTP response. | ||
| */ | ||
| responseAlgorithms?: string[]; | ||
| logger?: Logger; | ||
| } | ||
| export declare const validateChecksumFromResponse: (response: HttpResponse, { config, responseAlgorithms, logger }: ValidateChecksumFromResponseOptions) => Promise<void>; |
| export { Md5, Md5Js, Md5Node } from "@smithy/core/checksum"; |
| export { Sha1Js, Sha1Js as Sha1 } from "./sha1/Sha1Js"; | ||
| export declare const Sha1Node: symbol; | ||
| export { Sha256, Sha256Js, Sha256Node, Sha256WebCrypto } from "@smithy/core/checksum"; |
| export { Sha1Js } from "./sha1/Sha1Js"; | ||
| export { Sha1Node, Sha1Node as Sha1 } from "./sha1/Sha1Node"; | ||
| export { Sha1WebCrypto } from "./sha1/Sha1WebCrypto"; | ||
| export { Sha256, Sha256Js, Sha256Node } from "@smithy/core/checksum"; |
| import type { Checksum, SourceData } from "@smithy/types"; | ||
| /** | ||
| * Pure JS SHA-1 implementation with HMAC support. | ||
| * Non-destructive digest for plain hash — safe to call digest() multiple times. | ||
| * @see https://csrc.nist.gov/pubs/fips/180-4/upd1/final | ||
| * @public | ||
| */ | ||
| export declare class Sha1Js implements Checksum { | ||
| readonly digestLength = 20; | ||
| private state; | ||
| private w?; | ||
| private buffer; | ||
| private bufferLength; | ||
| private bytesHashed; | ||
| private finished; | ||
| private readonly inner?; | ||
| private readonly outer?; | ||
| constructor(secret?: SourceData); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| private digestSync; | ||
| private static normalizeKey; | ||
| private hashBuffer; | ||
| private hashBufferWith; | ||
| } |
| import type { Checksum, SourceData } from "@smithy/types"; | ||
| /** | ||
| * SHA-1 using Node.js crypto native implementation when available, | ||
| * falling back to the pure JS implementation. | ||
| * @public | ||
| */ | ||
| export interface Sha1Node extends Checksum { | ||
| readonly digestLength: 20; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare const Sha1Node: new (secret?: SourceData) => Sha1Node; |
| import type { Checksum, SourceData } from "@smithy/types"; | ||
| /** | ||
| * SHA-1 using the Web Crypto API (crypto.subtle) when available, | ||
| * falling back to the pure JS implementation. | ||
| * | ||
| * Caution: buffers data entirely in memory since WebCrypto requires | ||
| * all data at once for digest(). | ||
| * @public | ||
| */ | ||
| export declare class Sha1WebCrypto implements Checksum { | ||
| readonly digestLength: 20; | ||
| private readonly secret?; | ||
| private pending; | ||
| private pendingBytes; | ||
| private fallback?; | ||
| private finished; | ||
| constructor(secret?: SourceData); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| private switchToFallback; | ||
| } |
| import { Checksum } from "@smithy/types"; | ||
| export declare class Crc32cJs implements Checksum { | ||
| readonly digestLength = 4; | ||
| private crc; | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } |
| import { Checksum } from "@smithy/types"; | ||
| export interface Crc32cNode extends Checksum { | ||
| readonly digestLength: 4; | ||
| } | ||
| export declare const Crc32cNode: new () => Crc32cNode; |
| import { ChecksumConstructor } from "@smithy/types"; | ||
| export declare const crc64NvmeCrtContainer: { | ||
| CrtCrc64Nvme: null | ChecksumConstructor; | ||
| }; |
| import { Checksum } from "@smithy/types"; | ||
| export declare class Crc64Nvme implements Checksum { | ||
| private impl; | ||
| constructor(); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } |
| import { Checksum } from "@smithy/types"; | ||
| export declare class Crc64NvmeJs implements Checksum { | ||
| private c1; | ||
| private c2; | ||
| constructor(); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } |
| export { Crc32cJs, Crc32cJs as Crc32c } from "./crc32c/Crc32cJs"; | ||
| export declare const Crc32cNode: symbol; | ||
| export { | ||
| Crc64NvmeJs, | ||
| Crc64NvmeJs as Crc64Nvme, | ||
| } from "./crc64-nvme/Crc64NvmeJs"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { Crc32, Crc32Js, Crc32Node } from "@smithy/core/checksum"; |
| export { Crc32cJs } from "./crc32c/Crc32cJs"; | ||
| export { Crc32cNode, Crc32cNode as Crc32c } from "./crc32c/Crc32cNode"; | ||
| export { Crc64Nvme } from "./crc64-nvme/Crc64Nvme"; | ||
| export { Crc64NvmeJs } from "./crc64-nvme/Crc64NvmeJs"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { Crc32, Crc32Js, Crc32Node } from "@smithy/core/checksum"; |
| import { | ||
| BodyLengthCalculator, | ||
| ChecksumConstructor, | ||
| Encoder, | ||
| GetAwsChunkedEncodingStream, | ||
| HashConstructor, | ||
| Provider, | ||
| StreamCollector, | ||
| StreamHasher, | ||
| } from "@smithy/types"; | ||
| import { | ||
| RequestChecksumCalculation, | ||
| ResponseChecksumValidation, | ||
| } from "./constants"; | ||
| import { FlexibleChecksumsInputConfig } from "./resolveFlexibleChecksumsConfig"; | ||
| export interface PreviouslyResolved { | ||
| base64Encoder: Encoder; | ||
| bodyLengthChecker: BodyLengthCalculator; | ||
| getAwsChunkedEncodingStream: GetAwsChunkedEncodingStream; | ||
| md5: ChecksumConstructor | HashConstructor; | ||
| requestChecksumCalculation: Provider<RequestChecksumCalculation>; | ||
| responseChecksumValidation: Provider<ResponseChecksumValidation>; | ||
| sha1: ChecksumConstructor | HashConstructor; | ||
| sha256: ChecksumConstructor | HashConstructor; | ||
| streamHasher: StreamHasher<any>; | ||
| streamCollector: StreamCollector; | ||
| requestStreamBufferSize: number; | ||
| checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"]; | ||
| } |
| export declare const RequestChecksumCalculation: { | ||
| readonly WHEN_SUPPORTED: "WHEN_SUPPORTED"; | ||
| readonly WHEN_REQUIRED: "WHEN_REQUIRED"; | ||
| }; | ||
| export type RequestChecksumCalculation = | ||
| (typeof RequestChecksumCalculation)[keyof typeof RequestChecksumCalculation]; | ||
| export declare const DEFAULT_REQUEST_CHECKSUM_CALCULATION: "WHEN_SUPPORTED"; | ||
| export declare const ResponseChecksumValidation: { | ||
| readonly WHEN_SUPPORTED: "WHEN_SUPPORTED"; | ||
| readonly WHEN_REQUIRED: "WHEN_REQUIRED"; | ||
| }; | ||
| export type ResponseChecksumValidation = | ||
| (typeof ResponseChecksumValidation)[keyof typeof ResponseChecksumValidation]; | ||
| export declare const DEFAULT_RESPONSE_CHECKSUM_VALIDATION: "WHEN_SUPPORTED"; | ||
| export declare enum ChecksumAlgorithm { | ||
| MD5 = "MD5", | ||
| CRC32 = "CRC32", | ||
| CRC32C = "CRC32C", | ||
| CRC64NVME = "CRC64NVME", | ||
| SHA1 = "SHA1", | ||
| SHA256 = "SHA256", | ||
| } | ||
| export declare enum ChecksumLocation { | ||
| HEADER = "header", | ||
| TRAILER = "trailer", | ||
| } | ||
| export declare const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; |
| import { RelativeMiddlewareOptions, SerializeMiddleware } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| export interface FlexibleChecksumsInputMiddlewareConfig { | ||
| requestValidationModeMember?: string; | ||
| } | ||
| export declare const flexibleChecksumsInputMiddlewareOptions: RelativeMiddlewareOptions; | ||
| export declare const flexibleChecksumsInputMiddleware: ( | ||
| config: PreviouslyResolved, | ||
| middlewareConfig: FlexibleChecksumsInputMiddlewareConfig | ||
| ) => SerializeMiddleware<any, any>; |
| import { BuildHandlerOptions, BuildMiddleware } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| export interface FlexibleChecksumsRequestMiddlewareConfig { | ||
| requestChecksumRequired: boolean; | ||
| requestAlgorithmMember?: { | ||
| name: string; | ||
| httpHeader?: string; | ||
| }; | ||
| } | ||
| export declare const flexibleChecksumsMiddlewareOptions: BuildHandlerOptions; | ||
| export declare const flexibleChecksumsMiddleware: ( | ||
| config: PreviouslyResolved, | ||
| middlewareConfig: FlexibleChecksumsRequestMiddlewareConfig | ||
| ) => BuildMiddleware<any, any>; |
| import { | ||
| DeserializeMiddleware, | ||
| RelativeMiddlewareOptions, | ||
| } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| export interface FlexibleChecksumsResponseMiddlewareConfig { | ||
| requestValidationModeMember?: string; | ||
| responseAlgorithms?: string[]; | ||
| } | ||
| export declare const flexibleChecksumsResponseMiddlewareOptions: RelativeMiddlewareOptions; | ||
| export declare const flexibleChecksumsResponseMiddleware: ( | ||
| config: PreviouslyResolved, | ||
| middlewareConfig: FlexibleChecksumsResponseMiddlewareConfig | ||
| ) => DeserializeMiddleware<any, any>; |
| import { ChecksumConstructor, Encoder, HashConstructor } from "@smithy/types"; | ||
| export interface GetChecksumDigestOptions { | ||
| checksumAlgorithmFn: ChecksumConstructor | HashConstructor; | ||
| base64Encoder: Encoder; | ||
| } | ||
| export declare const getChecksum: ( | ||
| body: unknown, | ||
| { checksumAlgorithmFn, base64Encoder }: GetChecksumDigestOptions | ||
| ) => Promise<string>; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| import { RequestChecksumCalculation } from "./constants"; | ||
| export interface GetChecksumAlgorithmForRequestOptions { | ||
| requestChecksumRequired: boolean; | ||
| requestAlgorithmMember?: string; | ||
| requestChecksumCalculation: RequestChecksumCalculation; | ||
| } | ||
| export declare const getChecksumAlgorithmForRequest: ( | ||
| input: any, | ||
| { | ||
| requestChecksumRequired, | ||
| requestAlgorithmMember, | ||
| requestChecksumCalculation, | ||
| }: GetChecksumAlgorithmForRequestOptions | ||
| ) => ChecksumAlgorithm | string | undefined; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export declare const getChecksumAlgorithmListForResponse: ( | ||
| responseAlgorithms?: string[] | ||
| ) => ChecksumAlgorithm[]; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export declare const getChecksumLocationName: ( | ||
| algorithm: ChecksumAlgorithm | string | ||
| ) => string; |
| import { Pluggable } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| import { FlexibleChecksumsInputMiddlewareConfig } from "./flexibleChecksumsInputMiddleware"; | ||
| import { FlexibleChecksumsRequestMiddlewareConfig } from "./flexibleChecksumsMiddleware"; | ||
| import { FlexibleChecksumsResponseMiddlewareConfig } from "./flexibleChecksumsResponseMiddleware"; | ||
| export interface FlexibleChecksumsMiddlewareConfig | ||
| extends FlexibleChecksumsRequestMiddlewareConfig, | ||
| FlexibleChecksumsInputMiddlewareConfig, | ||
| FlexibleChecksumsResponseMiddlewareConfig {} | ||
| export declare const getFlexibleChecksumsPlugin: ( | ||
| config: PreviouslyResolved, | ||
| middlewareConfig: FlexibleChecksumsMiddlewareConfig | ||
| ) => Pluggable<any, any>; |
| import { HeaderBag } from "@smithy/types"; | ||
| export declare const hasHeader: (header: string, headers: HeaderBag) => boolean; |
| import { HeaderBag } from "@smithy/types"; | ||
| export declare const hasHeaderWithPrefix: ( | ||
| headerPrefix: string, | ||
| headers: HeaderBag | ||
| ) => boolean; |
| export { | ||
| ENV_REQUEST_CHECKSUM_CALCULATION, | ||
| CONFIG_REQUEST_CHECKSUM_CALCULATION, | ||
| NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, | ||
| } from "./NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS"; | ||
| export { | ||
| ENV_RESPONSE_CHECKSUM_VALIDATION, | ||
| CONFIG_RESPONSE_CHECKSUM_VALIDATION, | ||
| NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, | ||
| } from "./NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS"; | ||
| export { | ||
| RequestChecksumCalculation, | ||
| DEFAULT_REQUEST_CHECKSUM_CALCULATION, | ||
| ResponseChecksumValidation, | ||
| DEFAULT_RESPONSE_CHECKSUM_VALIDATION, | ||
| ChecksumAlgorithm, | ||
| ChecksumLocation, | ||
| DEFAULT_CHECKSUM_ALGORITHM, | ||
| } from "./constants"; | ||
| export { FlexibleChecksumsRequestMiddlewareConfig } from "./flexibleChecksumsMiddleware"; | ||
| export { | ||
| flexibleChecksumsMiddlewareOptions, | ||
| flexibleChecksumsMiddleware, | ||
| } from "./flexibleChecksumsMiddleware"; | ||
| export { FlexibleChecksumsMiddlewareConfig } from "./getFlexibleChecksumsPlugin"; | ||
| export { getFlexibleChecksumsPlugin } from "./getFlexibleChecksumsPlugin"; | ||
| export { | ||
| FlexibleChecksumsInputConfig, | ||
| FlexibleChecksumsResolvedConfig, | ||
| } from "./resolveFlexibleChecksumsConfig"; | ||
| export { resolveFlexibleChecksumsConfig } from "./resolveFlexibleChecksumsConfig"; |
| export declare const isChecksumWithPartNumber: (checksum: string) => boolean; |
| export declare const isStreaming: (body: unknown) => boolean; |
| import { LoadedConfigSelectors } from "@smithy/core/config"; | ||
| import { RequestChecksumCalculation } from "./constants"; | ||
| export declare const ENV_REQUEST_CHECKSUM_CALCULATION = | ||
| "AWS_REQUEST_CHECKSUM_CALCULATION"; | ||
| export declare const CONFIG_REQUEST_CHECKSUM_CALCULATION = | ||
| "request_checksum_calculation"; | ||
| export declare const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS: LoadedConfigSelectors<RequestChecksumCalculation>; |
| import { LoadedConfigSelectors } from "@smithy/core/config"; | ||
| import { ResponseChecksumValidation } from "./constants"; | ||
| export declare const ENV_RESPONSE_CHECKSUM_VALIDATION = | ||
| "AWS_RESPONSE_CHECKSUM_VALIDATION"; | ||
| export declare const CONFIG_RESPONSE_CHECKSUM_VALIDATION = | ||
| "response_checksum_validation"; | ||
| export declare const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS: LoadedConfigSelectors<ResponseChecksumValidation>; |
| import { ChecksumConstructor, Provider } from "@smithy/types"; | ||
| import { | ||
| RequestChecksumCalculation, | ||
| ResponseChecksumValidation, | ||
| } from "./constants"; | ||
| export interface FlexibleChecksumsInputConfig { | ||
| requestChecksumCalculation?: | ||
| | RequestChecksumCalculation | ||
| | Provider<RequestChecksumCalculation>; | ||
| responseChecksumValidation?: | ||
| | ResponseChecksumValidation | ||
| | Provider<ResponseChecksumValidation>; | ||
| requestStreamBufferSize?: number | false; | ||
| checksumAlgorithms?: { | ||
| CRC32?: ChecksumConstructor; | ||
| CRC32C?: ChecksumConstructor; | ||
| CRC64NVME?: ChecksumConstructor; | ||
| SHA1?: ChecksumConstructor; | ||
| SHA256?: ChecksumConstructor; | ||
| } & { | ||
| [algorithmId: string]: ChecksumConstructor; | ||
| }; | ||
| } | ||
| export interface FlexibleChecksumsResolvedConfig { | ||
| requestChecksumCalculation: Provider<RequestChecksumCalculation>; | ||
| responseChecksumValidation: Provider<ResponseChecksumValidation>; | ||
| requestStreamBufferSize: number; | ||
| checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"]; | ||
| } | ||
| export declare const resolveFlexibleChecksumsConfig: <T>( | ||
| input: T & FlexibleChecksumsInputConfig | ||
| ) => T & FlexibleChecksumsResolvedConfig; |
| import { ChecksumConstructor, HashConstructor } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| import { ChecksumAlgorithm } from "./constants"; | ||
| export declare const selectChecksumAlgorithmFunction: ( | ||
| checksumAlgorithm: ChecksumAlgorithm | string, | ||
| config: PreviouslyResolved | ||
| ) => ChecksumConstructor | HashConstructor; |
| import { ChecksumConstructor, HashConstructor } from "@smithy/types"; | ||
| export declare const stringHasher: ( | ||
| checksumAlgorithmFn: ChecksumConstructor | HashConstructor, | ||
| body: any | ||
| ) => Promise<Uint8Array>; |
| export declare enum SelectorType { | ||
| ENV = "env", | ||
| CONFIG = "shared config entry", | ||
| } | ||
| export declare const stringUnionSelector: <U extends object, K extends keyof U>( | ||
| obj: Record<string, string | undefined>, | ||
| key: string, | ||
| union: U, | ||
| type: SelectorType | ||
| ) => U[K] | undefined; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export declare const CLIENT_SUPPORTED_ALGORITHMS: ChecksumAlgorithm[]; | ||
| export declare const PRIORITY_ORDER_ALGORITHMS: ChecksumAlgorithm[]; |
| import { HttpResponse } from "@smithy/core/protocols"; | ||
| import { Logger } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| export interface ValidateChecksumFromResponseOptions { | ||
| config: PreviouslyResolved; | ||
| responseAlgorithms?: string[]; | ||
| logger?: Logger; | ||
| } | ||
| export declare const validateChecksumFromResponse: ( | ||
| response: HttpResponse, | ||
| { config, responseAlgorithms, logger }: ValidateChecksumFromResponseOptions | ||
| ) => Promise<void>; |
| export { Md5, Md5Js, Md5Node } from "@smithy/core/checksum"; |
| export { Sha1Js, Sha1Js as Sha1 } from "./sha1/Sha1Js"; | ||
| export declare const Sha1Node: symbol; | ||
| export { | ||
| Sha256, | ||
| Sha256Js, | ||
| Sha256Node, | ||
| Sha256WebCrypto, | ||
| } from "@smithy/core/checksum"; |
| export { Sha1Js } from "./sha1/Sha1Js"; | ||
| export { Sha1Node, Sha1Node as Sha1 } from "./sha1/Sha1Node"; | ||
| export { Sha1WebCrypto } from "./sha1/Sha1WebCrypto"; | ||
| export { Sha256, Sha256Js, Sha256Node } from "@smithy/core/checksum"; |
| import { Checksum, SourceData } from "@smithy/types"; | ||
| export declare class Sha1Js implements Checksum { | ||
| readonly digestLength = 20; | ||
| private state; | ||
| private w?; | ||
| private buffer; | ||
| private bufferLength; | ||
| private bytesHashed; | ||
| private finished; | ||
| private readonly inner?; | ||
| private readonly outer?; | ||
| constructor(secret?: SourceData); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| private digestSync; | ||
| private static normalizeKey; | ||
| private hashBuffer; | ||
| private hashBufferWith; | ||
| } |
| import { Checksum, SourceData } from "@smithy/types"; | ||
| export interface Sha1Node extends Checksum { | ||
| readonly digestLength: 20; | ||
| } | ||
| export declare const Sha1Node: new (secret?: SourceData) => Sha1Node; |
| import { Checksum, SourceData } from "@smithy/types"; | ||
| export declare class Sha1WebCrypto implements Checksum { | ||
| readonly digestLength: 20; | ||
| private readonly secret?; | ||
| private pending; | ||
| private pendingBytes; | ||
| private fallback?; | ||
| private finished; | ||
| constructor(secret?: SourceData); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| private switchToFallback; | ||
| } |
| /** | ||
| * Do not edit: | ||
| * This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
| */ | ||
| export * from "./dist-types/submodules/flexible-checksums/index"; |
| /** | ||
| * Do not edit: | ||
| * This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
| */ | ||
| module.exports = require("./dist-cjs/submodules/flexible-checksums/index.js"); |
+5
| /** | ||
| * Do not edit: | ||
| * This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
| */ | ||
| export * from "./dist-types/submodules/md5/index"; |
+5
| /** | ||
| * Do not edit: | ||
| * This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
| */ | ||
| module.exports = require("./dist-cjs/submodules/md5/index.js"); |
+5
| /** | ||
| * Do not edit: | ||
| * This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
| */ | ||
| export * from "./dist-types/submodules/sha/index"; |
+5
| /** | ||
| * Do not edit: | ||
| * This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
| */ | ||
| module.exports = require("./dist-cjs/submodules/sha/index.js"); |
+5
-551
@@ -1,550 +0,6 @@ | ||
| const { setFeature } = require("@aws-sdk/core/client"); | ||
| const { HttpRequest } = require("@smithy/core/protocols"); | ||
| const { isArrayBuffer, toUint8Array, createBufferedReadable, createChecksumStream } = require("@smithy/core/serde"); | ||
| const { AwsCrc32c } = require("@aws-crypto/crc32c"); | ||
| const { AwsCrc32 } = require("@aws-crypto/crc32"); | ||
| const { numToUint8 } = require("@aws-crypto/util"); | ||
| const zlib = require("node:zlib"); | ||
| const { normalizeProvider } = require("@smithy/core/client"); | ||
| const generateCRC64NVMETable = () => { | ||
| const sliceLength = 8; | ||
| const tables = new Array(sliceLength); | ||
| for (let slice = 0; slice < sliceLength; slice++) { | ||
| const table = new Array(512); | ||
| for (let i = 0; i < 256; i++) { | ||
| let crc = BigInt(i); | ||
| for (let j = 0; j < 8 * (slice + 1); j++) { | ||
| if (crc & 1n) { | ||
| crc = (crc >> 1n) ^ 0x9a6c9329ac4bc9b5n; | ||
| } | ||
| else { | ||
| crc = crc >> 1n; | ||
| } | ||
| } | ||
| table[i * 2] = Number((crc >> 32n) & 0xffffffffn); | ||
| table[i * 2 + 1] = Number(crc & 0xffffffffn); | ||
| } | ||
| tables[slice] = new Uint32Array(table); | ||
| } | ||
| return tables; | ||
| }; | ||
| let CRC64_NVME_REVERSED_TABLE; | ||
| let t0, t1, t2, t3; | ||
| let t4, t5, t6, t7; | ||
| const ensureTablesInitialized = () => { | ||
| if (!CRC64_NVME_REVERSED_TABLE) { | ||
| CRC64_NVME_REVERSED_TABLE = generateCRC64NVMETable(); | ||
| [t0, t1, t2, t3, t4, t5, t6, t7] = CRC64_NVME_REVERSED_TABLE; | ||
| } | ||
| }; | ||
| class Crc64Nvme { | ||
| c1 = 0; | ||
| c2 = 0; | ||
| constructor() { | ||
| ensureTablesInitialized(); | ||
| this.reset(); | ||
| } | ||
| update(data) { | ||
| const len = data.length; | ||
| let i = 0; | ||
| let crc1 = this.c1; | ||
| let crc2 = this.c2; | ||
| while (i + 8 <= len) { | ||
| const idx0 = ((crc2 ^ data[i++]) & 255) << 1; | ||
| const idx1 = (((crc2 >>> 8) ^ data[i++]) & 255) << 1; | ||
| const idx2 = (((crc2 >>> 16) ^ data[i++]) & 255) << 1; | ||
| const idx3 = (((crc2 >>> 24) ^ data[i++]) & 255) << 1; | ||
| const idx4 = ((crc1 ^ data[i++]) & 255) << 1; | ||
| const idx5 = (((crc1 >>> 8) ^ data[i++]) & 255) << 1; | ||
| const idx6 = (((crc1 >>> 16) ^ data[i++]) & 255) << 1; | ||
| const idx7 = (((crc1 >>> 24) ^ data[i++]) & 255) << 1; | ||
| crc1 = t7[idx0] ^ t6[idx1] ^ t5[idx2] ^ t4[idx3] ^ t3[idx4] ^ t2[idx5] ^ t1[idx6] ^ t0[idx7]; | ||
| crc2 = | ||
| t7[idx0 + 1] ^ | ||
| t6[idx1 + 1] ^ | ||
| t5[idx2 + 1] ^ | ||
| t4[idx3 + 1] ^ | ||
| t3[idx4 + 1] ^ | ||
| t2[idx5 + 1] ^ | ||
| t1[idx6 + 1] ^ | ||
| t0[idx7 + 1]; | ||
| } | ||
| while (i < len) { | ||
| const idx = ((crc2 ^ data[i]) & 255) << 1; | ||
| crc2 = ((crc2 >>> 8) | ((crc1 & 255) << 24)) >>> 0; | ||
| crc1 = (crc1 >>> 8) ^ t0[idx]; | ||
| crc2 ^= t0[idx + 1]; | ||
| i++; | ||
| } | ||
| this.c1 = crc1; | ||
| this.c2 = crc2; | ||
| } | ||
| async digest() { | ||
| const c1 = this.c1 ^ 4294967295; | ||
| const c2 = this.c2 ^ 4294967295; | ||
| return new Uint8Array([ | ||
| c1 >>> 24, | ||
| (c1 >>> 16) & 255, | ||
| (c1 >>> 8) & 255, | ||
| c1 & 255, | ||
| c2 >>> 24, | ||
| (c2 >>> 16) & 255, | ||
| (c2 >>> 8) & 255, | ||
| c2 & 255, | ||
| ]); | ||
| } | ||
| reset() { | ||
| this.c1 = 4294967295; | ||
| this.c2 = 4294967295; | ||
| } | ||
| } | ||
| const crc64NvmeCrtContainer = { | ||
| CrtCrc64Nvme: null, | ||
| }; | ||
| const RequestChecksumCalculation = { | ||
| WHEN_SUPPORTED: "WHEN_SUPPORTED", | ||
| WHEN_REQUIRED: "WHEN_REQUIRED", | ||
| }; | ||
| const DEFAULT_REQUEST_CHECKSUM_CALCULATION = RequestChecksumCalculation.WHEN_SUPPORTED; | ||
| const ResponseChecksumValidation = { | ||
| WHEN_SUPPORTED: "WHEN_SUPPORTED", | ||
| WHEN_REQUIRED: "WHEN_REQUIRED", | ||
| }; | ||
| const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.WHEN_SUPPORTED; | ||
| var ChecksumAlgorithm; | ||
| (function (ChecksumAlgorithm) { | ||
| ChecksumAlgorithm["MD5"] = "MD5"; | ||
| ChecksumAlgorithm["CRC32"] = "CRC32"; | ||
| ChecksumAlgorithm["CRC32C"] = "CRC32C"; | ||
| ChecksumAlgorithm["CRC64NVME"] = "CRC64NVME"; | ||
| ChecksumAlgorithm["SHA1"] = "SHA1"; | ||
| ChecksumAlgorithm["SHA256"] = "SHA256"; | ||
| })(ChecksumAlgorithm || (ChecksumAlgorithm = {})); | ||
| var ChecksumLocation; | ||
| (function (ChecksumLocation) { | ||
| ChecksumLocation["HEADER"] = "header"; | ||
| ChecksumLocation["TRAILER"] = "trailer"; | ||
| })(ChecksumLocation || (ChecksumLocation = {})); | ||
| const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; | ||
| var SelectorType; | ||
| (function (SelectorType) { | ||
| SelectorType["ENV"] = "env"; | ||
| SelectorType["CONFIG"] = "shared config entry"; | ||
| })(SelectorType || (SelectorType = {})); | ||
| const stringUnionSelector = (obj, key, union, type) => { | ||
| if (!(key in obj)) | ||
| return undefined; | ||
| const value = obj[key].toUpperCase(); | ||
| if (!Object.values(union).includes(value)) { | ||
| throw new TypeError(`Cannot load ${type} '${key}'. Expected one of ${Object.values(union)}, got '${obj[key]}'.`); | ||
| } | ||
| return value; | ||
| }; | ||
| const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION"; | ||
| const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation"; | ||
| const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS = { | ||
| environmentVariableSelector: (env) => stringUnionSelector(env, ENV_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.ENV), | ||
| configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.CONFIG), | ||
| default: DEFAULT_REQUEST_CHECKSUM_CALCULATION, | ||
| }; | ||
| const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION"; | ||
| const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation"; | ||
| const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS = { | ||
| environmentVariableSelector: (env) => stringUnionSelector(env, ENV_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.ENV), | ||
| configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.CONFIG), | ||
| default: DEFAULT_RESPONSE_CHECKSUM_VALIDATION, | ||
| }; | ||
| const getChecksumAlgorithmForRequest = (input, { requestChecksumRequired, requestAlgorithmMember, requestChecksumCalculation }) => { | ||
| if (!requestAlgorithmMember) { | ||
| return requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired | ||
| ? DEFAULT_CHECKSUM_ALGORITHM | ||
| : undefined; | ||
| } | ||
| if (!input[requestAlgorithmMember]) { | ||
| return undefined; | ||
| } | ||
| const checksumAlgorithm = input[requestAlgorithmMember]; | ||
| return checksumAlgorithm; | ||
| }; | ||
| const getChecksumLocationName = (algorithm) => algorithm === ChecksumAlgorithm.MD5 ? "content-md5" : `x-amz-checksum-${algorithm.toLowerCase()}`; | ||
| const hasHeader = (header, headers) => { | ||
| const soughtHeader = header.toLowerCase(); | ||
| for (const headerName of Object.keys(headers)) { | ||
| if (soughtHeader === headerName.toLowerCase()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; | ||
| const hasHeaderWithPrefix = (headerPrefix, headers) => { | ||
| const soughtHeaderPrefix = headerPrefix.toLowerCase(); | ||
| for (const headerName of Object.keys(headers)) { | ||
| if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; | ||
| const isStreaming = (body) => body !== undefined && typeof body !== "string" && !ArrayBuffer.isView(body) && !isArrayBuffer(body); | ||
| class NodeCrc32 { | ||
| checksum = 0; | ||
| update(data) { | ||
| this.checksum = zlib.crc32(data, this.checksum); | ||
| } | ||
| async digest() { | ||
| return numToUint8(this.checksum); | ||
| } | ||
| reset() { | ||
| this.checksum = 0; | ||
| } | ||
| } | ||
| const getCrc32ChecksumAlgorithmFunction = () => { | ||
| if (typeof zlib.crc32 === "undefined") { | ||
| return AwsCrc32; | ||
| } | ||
| return NodeCrc32; | ||
| }; | ||
| const CLIENT_SUPPORTED_ALGORITHMS = [ | ||
| ChecksumAlgorithm.CRC32, | ||
| ChecksumAlgorithm.CRC32C, | ||
| ChecksumAlgorithm.CRC64NVME, | ||
| ChecksumAlgorithm.SHA1, | ||
| ChecksumAlgorithm.SHA256, | ||
| ]; | ||
| const PRIORITY_ORDER_ALGORITHMS = [ | ||
| ChecksumAlgorithm.SHA256, | ||
| ChecksumAlgorithm.SHA1, | ||
| ChecksumAlgorithm.CRC32, | ||
| ChecksumAlgorithm.CRC32C, | ||
| ChecksumAlgorithm.CRC64NVME, | ||
| ]; | ||
| const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => { | ||
| const { checksumAlgorithms = {} } = config; | ||
| switch (checksumAlgorithm) { | ||
| case ChecksumAlgorithm.MD5: | ||
| return checksumAlgorithms?.MD5 ?? config.md5; | ||
| case ChecksumAlgorithm.CRC32: | ||
| return checksumAlgorithms?.CRC32 ?? getCrc32ChecksumAlgorithmFunction(); | ||
| case ChecksumAlgorithm.CRC32C: | ||
| return checksumAlgorithms?.CRC32C ?? AwsCrc32c; | ||
| case ChecksumAlgorithm.CRC64NVME: | ||
| if (typeof crc64NvmeCrtContainer.CrtCrc64Nvme !== "function") { | ||
| return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme; | ||
| } | ||
| return checksumAlgorithms?.CRC64NVME ?? crc64NvmeCrtContainer.CrtCrc64Nvme; | ||
| case ChecksumAlgorithm.SHA1: | ||
| return checksumAlgorithms?.SHA1 ?? config.sha1; | ||
| case ChecksumAlgorithm.SHA256: | ||
| return checksumAlgorithms?.SHA256 ?? config.sha256; | ||
| default: | ||
| if (checksumAlgorithms?.[checksumAlgorithm]) { | ||
| return checksumAlgorithms[checksumAlgorithm]; | ||
| } | ||
| throw new Error(`The checksum algorithm "${checksumAlgorithm}" is not supported by the client.` + | ||
| ` Select one of ${CLIENT_SUPPORTED_ALGORITHMS}, or provide an implementation to ` + | ||
| ` the client constructor checksums field.`); | ||
| } | ||
| }; | ||
| const stringHasher = (checksumAlgorithmFn, body) => { | ||
| const hash = new checksumAlgorithmFn(); | ||
| hash.update(toUint8Array(body || "")); | ||
| return hash.digest(); | ||
| }; | ||
| const flexibleChecksumsMiddlewareOptions = { | ||
| name: "flexibleChecksumsMiddleware", | ||
| step: "build", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| if (!HttpRequest.isInstance(args.request)) { | ||
| return next(args); | ||
| } | ||
| if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) { | ||
| return next(args); | ||
| } | ||
| const { request, input } = args; | ||
| const { body: requestBody, headers } = request; | ||
| const { base64Encoder, streamHasher } = config; | ||
| const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; | ||
| const requestChecksumCalculation = await config.requestChecksumCalculation(); | ||
| const requestAlgorithmMemberName = requestAlgorithmMember?.name; | ||
| const requestAlgorithmMemberHttpHeader = requestAlgorithmMember?.httpHeader; | ||
| if (requestAlgorithmMemberName && !input[requestAlgorithmMemberName]) { | ||
| if (requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired) { | ||
| input[requestAlgorithmMemberName] = DEFAULT_CHECKSUM_ALGORITHM; | ||
| if (requestAlgorithmMemberHttpHeader) { | ||
| headers[requestAlgorithmMemberHttpHeader] = DEFAULT_CHECKSUM_ALGORITHM; | ||
| } | ||
| } | ||
| } | ||
| const checksumAlgorithm = getChecksumAlgorithmForRequest(input, { | ||
| requestChecksumRequired, | ||
| requestAlgorithmMember: requestAlgorithmMember?.name, | ||
| requestChecksumCalculation, | ||
| }); | ||
| let updatedBody = requestBody; | ||
| let updatedHeaders = headers; | ||
| if (checksumAlgorithm) { | ||
| switch (checksumAlgorithm) { | ||
| case ChecksumAlgorithm.CRC32: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32", "U"); | ||
| break; | ||
| case ChecksumAlgorithm.CRC32C: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V"); | ||
| break; | ||
| case ChecksumAlgorithm.CRC64NVME: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W"); | ||
| break; | ||
| case ChecksumAlgorithm.SHA1: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X"); | ||
| break; | ||
| case ChecksumAlgorithm.SHA256: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA256", "Y"); | ||
| break; | ||
| } | ||
| const checksumLocationName = getChecksumLocationName(checksumAlgorithm); | ||
| const checksumAlgorithmFn = selectChecksumAlgorithmFunction(checksumAlgorithm, config); | ||
| if (isStreaming(requestBody)) { | ||
| const { getAwsChunkedEncodingStream, bodyLengthChecker } = config; | ||
| updatedBody = getAwsChunkedEncodingStream(typeof config.requestStreamBufferSize === "number" && config.requestStreamBufferSize >= 8 * 1024 | ||
| ? createBufferedReadable(requestBody, config.requestStreamBufferSize, context.logger) | ||
| : requestBody, { | ||
| base64Encoder, | ||
| bodyLengthChecker, | ||
| checksumLocationName, | ||
| checksumAlgorithmFn, | ||
| streamHasher, | ||
| }); | ||
| updatedHeaders = { | ||
| ...headers, | ||
| "content-encoding": headers["content-encoding"] | ||
| ? `${headers["content-encoding"]},aws-chunked` | ||
| : "aws-chunked", | ||
| "transfer-encoding": "chunked", | ||
| "x-amz-decoded-content-length": headers["content-length"], | ||
| "x-amz-content-sha256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER", | ||
| "x-amz-trailer": checksumLocationName, | ||
| }; | ||
| delete updatedHeaders["content-length"]; | ||
| } | ||
| else if (!hasHeader(checksumLocationName, headers)) { | ||
| const rawChecksum = await stringHasher(checksumAlgorithmFn, requestBody); | ||
| updatedHeaders = { | ||
| ...headers, | ||
| [checksumLocationName]: base64Encoder(rawChecksum), | ||
| }; | ||
| } | ||
| } | ||
| try { | ||
| const result = await next({ | ||
| ...args, | ||
| request: { | ||
| ...request, | ||
| headers: updatedHeaders, | ||
| body: updatedBody, | ||
| }, | ||
| }); | ||
| return result; | ||
| } | ||
| catch (e) { | ||
| if (e instanceof Error && e.name === "InvalidChunkSizeError") { | ||
| try { | ||
| if (!e.message.endsWith(".")) { | ||
| e.message += "."; | ||
| } | ||
| e.message += | ||
| " Set [requestStreamBufferSize=number e.g. 65_536] in client constructor to instruct AWS SDK to buffer your input stream."; | ||
| } | ||
| catch (ignored) { | ||
| } | ||
| } | ||
| throw e; | ||
| } | ||
| }; | ||
| const flexibleChecksumsInputMiddlewareOptions = { | ||
| name: "flexibleChecksumsInputMiddleware", | ||
| toMiddleware: "serializerMiddleware", | ||
| relation: "before", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| const flexibleChecksumsInputMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| const input = args.input; | ||
| const { requestValidationModeMember } = middlewareConfig; | ||
| const requestChecksumCalculation = await config.requestChecksumCalculation(); | ||
| const responseChecksumValidation = await config.responseChecksumValidation(); | ||
| switch (requestChecksumCalculation) { | ||
| case RequestChecksumCalculation.WHEN_REQUIRED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED", "a"); | ||
| break; | ||
| case RequestChecksumCalculation.WHEN_SUPPORTED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED", "Z"); | ||
| break; | ||
| } | ||
| switch (responseChecksumValidation) { | ||
| case ResponseChecksumValidation.WHEN_REQUIRED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED", "c"); | ||
| break; | ||
| case ResponseChecksumValidation.WHEN_SUPPORTED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED", "b"); | ||
| break; | ||
| } | ||
| if (requestValidationModeMember && !input[requestValidationModeMember]) { | ||
| if (responseChecksumValidation === ResponseChecksumValidation.WHEN_SUPPORTED) { | ||
| input[requestValidationModeMember] = "ENABLED"; | ||
| } | ||
| } | ||
| return next(args); | ||
| }; | ||
| const getChecksumAlgorithmListForResponse = (responseAlgorithms = []) => { | ||
| const validChecksumAlgorithms = []; | ||
| let i = PRIORITY_ORDER_ALGORITHMS.length; | ||
| for (const algorithm of responseAlgorithms) { | ||
| const priority = PRIORITY_ORDER_ALGORITHMS.indexOf(algorithm); | ||
| if (priority !== -1) { | ||
| validChecksumAlgorithms[priority] = algorithm; | ||
| } | ||
| else { | ||
| validChecksumAlgorithms[i++] = algorithm; | ||
| } | ||
| } | ||
| return validChecksumAlgorithms.filter(Boolean); | ||
| }; | ||
| const isChecksumWithPartNumber = (checksum) => { | ||
| const lastHyphenIndex = checksum.lastIndexOf("-"); | ||
| if (lastHyphenIndex !== -1) { | ||
| const numberPart = checksum.slice(lastHyphenIndex + 1); | ||
| if (!numberPart.startsWith("0")) { | ||
| const number = parseInt(numberPart, 10); | ||
| if (!isNaN(number) && number >= 1 && number <= 10000) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| }; | ||
| const getChecksum = async (body, { checksumAlgorithmFn, base64Encoder }) => base64Encoder(await stringHasher(checksumAlgorithmFn, body)); | ||
| const validateChecksumFromResponse = async (response, { config, responseAlgorithms, logger }) => { | ||
| const checksumAlgorithms = getChecksumAlgorithmListForResponse(responseAlgorithms); | ||
| const { body: responseBody, headers: responseHeaders } = response; | ||
| for (const algorithm of checksumAlgorithms) { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| const checksumFromResponse = responseHeaders[responseHeader]; | ||
| if (checksumFromResponse) { | ||
| let checksumAlgorithmFn; | ||
| try { | ||
| checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config); | ||
| } | ||
| catch (error) { | ||
| if (algorithm === ChecksumAlgorithm.CRC64NVME) { | ||
| logger?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`); | ||
| continue; | ||
| } | ||
| throw error; | ||
| } | ||
| const { base64Encoder } = config; | ||
| if (isStreaming(responseBody)) { | ||
| response.body = createChecksumStream({ | ||
| expectedChecksum: checksumFromResponse, | ||
| checksumSourceLocation: responseHeader, | ||
| checksum: new checksumAlgorithmFn(), | ||
| source: responseBody, | ||
| base64Encoder, | ||
| }); | ||
| return; | ||
| } | ||
| const checksum = await getChecksum(responseBody, { checksumAlgorithmFn, base64Encoder }); | ||
| if (checksum === checksumFromResponse) { | ||
| break; | ||
| } | ||
| throw new Error(`Checksum mismatch: expected "${checksum}" but received "${checksumFromResponse}"` + | ||
| ` in response header "${responseHeader}".`); | ||
| } | ||
| } | ||
| }; | ||
| const flexibleChecksumsResponseMiddlewareOptions = { | ||
| name: "flexibleChecksumsResponseMiddleware", | ||
| toMiddleware: "deserializerMiddleware", | ||
| relation: "after", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| const flexibleChecksumsResponseMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| if (!HttpRequest.isInstance(args.request)) { | ||
| return next(args); | ||
| } | ||
| const input = args.input; | ||
| const result = await next(args); | ||
| const response = result.response; | ||
| const { requestValidationModeMember, responseAlgorithms } = middlewareConfig; | ||
| if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") { | ||
| const { clientName, commandName } = context; | ||
| const customChecksumAlgorithms = Object.keys(config.checksumAlgorithms ?? {}).filter((algorithm) => { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| return response.headers[responseHeader] !== undefined; | ||
| }); | ||
| const algoList = getChecksumAlgorithmListForResponse([ | ||
| ...(responseAlgorithms ?? []), | ||
| ...customChecksumAlgorithms, | ||
| ]); | ||
| const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" && | ||
| commandName === "GetObjectCommand" && | ||
| algoList.every((algorithm) => { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| const checksumFromResponse = response.headers[responseHeader]; | ||
| return !checksumFromResponse || isChecksumWithPartNumber(checksumFromResponse); | ||
| }); | ||
| if (isS3WholeObjectMultipartGetResponseChecksum) { | ||
| return result; | ||
| } | ||
| await validateChecksumFromResponse(response, { | ||
| config, | ||
| responseAlgorithms: algoList, | ||
| logger: context.logger, | ||
| }); | ||
| } | ||
| return result; | ||
| }; | ||
| const getFlexibleChecksumsPlugin = (config, middlewareConfig) => ({ | ||
| applyToStack: (clientStack) => { | ||
| clientStack.add(flexibleChecksumsMiddleware(config, middlewareConfig), flexibleChecksumsMiddlewareOptions); | ||
| clientStack.addRelativeTo(flexibleChecksumsInputMiddleware(config, middlewareConfig), flexibleChecksumsInputMiddlewareOptions); | ||
| clientStack.addRelativeTo(flexibleChecksumsResponseMiddleware(config, middlewareConfig), flexibleChecksumsResponseMiddlewareOptions); | ||
| }, | ||
| }); | ||
| const resolveFlexibleChecksumsConfig = (input) => { | ||
| const { requestChecksumCalculation, responseChecksumValidation, requestStreamBufferSize } = input; | ||
| return Object.assign(input, { | ||
| requestChecksumCalculation: normalizeProvider(requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION), | ||
| responseChecksumValidation: normalizeProvider(responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION), | ||
| requestStreamBufferSize: Number(requestStreamBufferSize ?? 0), | ||
| checksumAlgorithms: input.checksumAlgorithms ?? {}, | ||
| }); | ||
| }; | ||
| const { Crc64Nvme, Crc64NvmeJs, crc64NvmeCrtContainer } = require("@aws-sdk/checksums/crc"); | ||
| exports.Crc64Nvme = Crc64Nvme; | ||
| exports.Crc64NvmeJs = Crc64NvmeJs; | ||
| exports.crc64NvmeCrtContainer = crc64NvmeCrtContainer; | ||
| const { CONFIG_REQUEST_CHECKSUM_CALCULATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ENV_REQUEST_CHECKSUM_CALCULATION, ENV_RESPONSE_CHECKSUM_VALIDATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, RequestChecksumCalculation, ResponseChecksumValidation, flexibleChecksumsMiddleware, flexibleChecksumsMiddlewareOptions, getFlexibleChecksumsPlugin, resolveFlexibleChecksumsConfig } = require("@aws-sdk/checksums/flexible-checksums"); | ||
| exports.CONFIG_REQUEST_CHECKSUM_CALCULATION = CONFIG_REQUEST_CHECKSUM_CALCULATION; | ||
@@ -554,3 +10,2 @@ exports.CONFIG_RESPONSE_CHECKSUM_VALIDATION = CONFIG_RESPONSE_CHECKSUM_VALIDATION; | ||
| exports.ChecksumLocation = ChecksumLocation; | ||
| exports.Crc64Nvme = Crc64Nvme; | ||
| exports.DEFAULT_CHECKSUM_ALGORITHM = DEFAULT_CHECKSUM_ALGORITHM; | ||
@@ -565,3 +20,2 @@ exports.DEFAULT_REQUEST_CHECKSUM_CALCULATION = DEFAULT_REQUEST_CHECKSUM_CALCULATION; | ||
| exports.ResponseChecksumValidation = ResponseChecksumValidation; | ||
| exports.crc64NvmeCrtContainer = crc64NvmeCrtContainer; | ||
| exports.flexibleChecksumsMiddleware = flexibleChecksumsMiddleware; | ||
@@ -568,0 +22,0 @@ exports.flexibleChecksumsMiddlewareOptions = flexibleChecksumsMiddlewareOptions; |
+2
-8
@@ -1,8 +0,2 @@ | ||
| export { Crc64Nvme } from "./crc64-nvme/Crc64Nvme"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, } from "./flexible-checksums/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS"; | ||
| export { ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, } from "./flexible-checksums/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS"; | ||
| export { RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, } from "./flexible-checksums/constants"; | ||
| export { flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware, } from "./flexible-checksums/flexibleChecksumsMiddleware"; | ||
| export { getFlexibleChecksumsPlugin } from "./flexible-checksums/getFlexibleChecksumsPlugin"; | ||
| export { resolveFlexibleChecksumsConfig } from "./flexible-checksums/resolveFlexibleChecksumsConfig"; | ||
| export { Crc64Nvme, Crc64NvmeJs, crc64NvmeCrtContainer } from "@aws-sdk/checksums/crc"; | ||
| export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware, getFlexibleChecksumsPlugin, resolveFlexibleChecksumsConfig, } from "@aws-sdk/checksums/flexible-checksums"; |
@@ -1,11 +0,3 @@ | ||
| export { Crc64Nvme } from "./crc64-nvme/Crc64Nvme"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, } from "./flexible-checksums/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS"; | ||
| export { ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, } from "./flexible-checksums/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS"; | ||
| export { RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, } from "./flexible-checksums/constants"; | ||
| export type { FlexibleChecksumsRequestMiddlewareConfig } from "./flexible-checksums/flexibleChecksumsMiddleware"; | ||
| export { flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware, } from "./flexible-checksums/flexibleChecksumsMiddleware"; | ||
| export type { FlexibleChecksumsMiddlewareConfig } from "./flexible-checksums/getFlexibleChecksumsPlugin"; | ||
| export { getFlexibleChecksumsPlugin } from "./flexible-checksums/getFlexibleChecksumsPlugin"; | ||
| export type { FlexibleChecksumsInputConfig, FlexibleChecksumsResolvedConfig, } from "./flexible-checksums/resolveFlexibleChecksumsConfig"; | ||
| export { resolveFlexibleChecksumsConfig } from "./flexible-checksums/resolveFlexibleChecksumsConfig"; | ||
| export { Crc64Nvme, Crc64NvmeJs, crc64NvmeCrtContainer } from "@aws-sdk/checksums/crc"; | ||
| export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware, getFlexibleChecksumsPlugin, resolveFlexibleChecksumsConfig, } from "@aws-sdk/checksums/flexible-checksums"; | ||
| export type { FlexibleChecksumsRequestMiddlewareConfig, FlexibleChecksumsMiddlewareConfig, FlexibleChecksumsInputConfig, FlexibleChecksumsResolvedConfig, } from "@aws-sdk/checksums/flexible-checksums"; |
@@ -1,14 +0,13 @@ | ||
| export { Crc64Nvme } from "./crc64-nvme/Crc64Nvme"; | ||
| export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container"; | ||
| export { | ||
| Crc64Nvme, | ||
| Crc64NvmeJs, | ||
| crc64NvmeCrtContainer, | ||
| } from "@aws-sdk/checksums/crc"; | ||
| export { | ||
| ENV_REQUEST_CHECKSUM_CALCULATION, | ||
| CONFIG_REQUEST_CHECKSUM_CALCULATION, | ||
| NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, | ||
| } from "./flexible-checksums/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS"; | ||
| export { | ||
| ENV_RESPONSE_CHECKSUM_VALIDATION, | ||
| CONFIG_RESPONSE_CHECKSUM_VALIDATION, | ||
| NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, | ||
| } from "./flexible-checksums/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS"; | ||
| export { | ||
| RequestChecksumCalculation, | ||
@@ -21,14 +20,12 @@ DEFAULT_REQUEST_CHECKSUM_CALCULATION, | ||
| DEFAULT_CHECKSUM_ALGORITHM, | ||
| } from "./flexible-checksums/constants"; | ||
| export { FlexibleChecksumsRequestMiddlewareConfig } from "./flexible-checksums/flexibleChecksumsMiddleware"; | ||
| export { | ||
| flexibleChecksumsMiddlewareOptions, | ||
| flexibleChecksumsMiddleware, | ||
| } from "./flexible-checksums/flexibleChecksumsMiddleware"; | ||
| export { FlexibleChecksumsMiddlewareConfig } from "./flexible-checksums/getFlexibleChecksumsPlugin"; | ||
| export { getFlexibleChecksumsPlugin } from "./flexible-checksums/getFlexibleChecksumsPlugin"; | ||
| getFlexibleChecksumsPlugin, | ||
| resolveFlexibleChecksumsConfig, | ||
| } from "@aws-sdk/checksums/flexible-checksums"; | ||
| export { | ||
| FlexibleChecksumsRequestMiddlewareConfig, | ||
| FlexibleChecksumsMiddlewareConfig, | ||
| FlexibleChecksumsInputConfig, | ||
| FlexibleChecksumsResolvedConfig, | ||
| } from "./flexible-checksums/resolveFlexibleChecksumsConfig"; | ||
| export { resolveFlexibleChecksumsConfig } from "./flexible-checksums/resolveFlexibleChecksumsConfig"; | ||
| } from "@aws-sdk/checksums/flexible-checksums"; |
+65
-8
| { | ||
| "name": "@aws-sdk/checksums", | ||
| "version": "3.1000.9", | ||
| "version": "3.1000.10", | ||
| "description": "Checksum algorithms and flexible checksums middleware for the AWS SDK", | ||
| "scripts": { | ||
| "benchmark": "node ./scripts/checksum-perf.mjs", | ||
| "build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs", | ||
@@ -14,2 +15,4 @@ "build:cjs": "node ../../scripts/compilation/inline", | ||
| "extract:docs": "api-extractor run --local", | ||
| "lint": "node ../../scripts/validation/submodules-linter.js", | ||
| "prebuild": "yarn lint", | ||
| "test": "yarn g:vitest run", | ||
@@ -25,2 +28,49 @@ "test:watch": "yarn g:vitest watch", | ||
| "types": "./dist-types/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist-types/index.d.ts", | ||
| "module": "./dist-es/index.js", | ||
| "node": "./dist-cjs/index.js", | ||
| "import": "./dist-es/index.js", | ||
| "require": "./dist-cjs/index.js" | ||
| }, | ||
| "./package.json": { | ||
| "module": "./package.json", | ||
| "node": "./package.json", | ||
| "import": "./package.json", | ||
| "require": "./package.json" | ||
| }, | ||
| "./crc": { | ||
| "types": "./dist-types/submodules/crc/index.d.ts", | ||
| "react-native": "./dist-es/submodules/crc/index.browser.js", | ||
| "browser": "./dist-es/submodules/crc/index.browser.js", | ||
| "module": "./dist-es/submodules/crc/index.js", | ||
| "node": "./dist-cjs/submodules/crc/index.js", | ||
| "import": "./dist-es/submodules/crc/index.js", | ||
| "require": "./dist-cjs/submodules/crc/index.js" | ||
| }, | ||
| "./flexible-checksums": { | ||
| "types": "./dist-types/submodules/flexible-checksums/index.d.ts", | ||
| "module": "./dist-es/submodules/flexible-checksums/index.js", | ||
| "node": "./dist-cjs/submodules/flexible-checksums/index.js", | ||
| "import": "./dist-es/submodules/flexible-checksums/index.js", | ||
| "require": "./dist-cjs/submodules/flexible-checksums/index.js" | ||
| }, | ||
| "./sha": { | ||
| "types": "./dist-types/submodules/sha/index.d.ts", | ||
| "react-native": "./dist-es/submodules/sha/index.browser.js", | ||
| "browser": "./dist-es/submodules/sha/index.browser.js", | ||
| "module": "./dist-es/submodules/sha/index.js", | ||
| "node": "./dist-cjs/submodules/sha/index.js", | ||
| "import": "./dist-es/submodules/sha/index.js", | ||
| "require": "./dist-cjs/submodules/sha/index.js" | ||
| }, | ||
| "./md5": { | ||
| "types": "./dist-types/submodules/md5/index.d.ts", | ||
| "module": "./dist-es/submodules/md5/index.js", | ||
| "node": "./dist-cjs/submodules/md5/index.js", | ||
| "import": "./dist-es/submodules/md5/index.js", | ||
| "require": "./dist-cjs/submodules/md5/index.js" | ||
| } | ||
| }, | ||
| "sideEffects": false, | ||
@@ -33,8 +83,5 @@ "author": { | ||
| "dependencies": { | ||
| "@aws-crypto/crc32": "5.2.0", | ||
| "@aws-crypto/crc32c": "5.2.0", | ||
| "@aws-crypto/util": "5.2.0", | ||
| "@aws-sdk/core": "^3.974.24", | ||
| "@aws-sdk/core": "^3.974.25", | ||
| "@aws-sdk/types": "^3.973.14", | ||
| "@smithy/core": "^3.27.0", | ||
| "@smithy/core": "^3.28.0", | ||
| "@smithy/types": "^4.15.0", | ||
@@ -61,9 +108,19 @@ "tslib": "^2.6.2" | ||
| "files": [ | ||
| "./crc.d.ts", | ||
| "./crc.js", | ||
| "./flexible-checksums.d.ts", | ||
| "./flexible-checksums.js", | ||
| "./md5.d.ts", | ||
| "./md5.js", | ||
| "./sha.d.ts", | ||
| "./sha.js", | ||
| "dist-*/**" | ||
| ], | ||
| "browser": { | ||
| "./dist-es/flexible-checksums/getCrc32ChecksumAlgorithmFunction": "./dist-es/flexible-checksums/getCrc32ChecksumAlgorithmFunction.browser" | ||
| "./dist-es/submodules/crc/index.js": "./dist-es/submodules/crc/index.browser.js", | ||
| "./dist-es/submodules/sha/index.js": "./dist-es/submodules/sha/index.browser.js" | ||
| }, | ||
| "react-native": { | ||
| "./dist-es/flexible-checksums/getCrc32ChecksumAlgorithmFunction": "./dist-es/flexible-checksums/getCrc32ChecksumAlgorithmFunction.browser" | ||
| "./dist-es/submodules/crc/index.js": "./dist-es/submodules/crc/index.browser.js", | ||
| "./dist-es/submodules/sha/index.js": "./dist-es/submodules/sha/index.browser.js" | ||
| }, | ||
@@ -70,0 +127,0 @@ "homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages-internal/checksums", |
| export const crc64NvmeCrtContainer = { | ||
| CrtCrc64Nvme: null, | ||
| }; |
| const generateCRC64NVMETable = () => { | ||
| const sliceLength = 8; | ||
| const tables = new Array(sliceLength); | ||
| for (let slice = 0; slice < sliceLength; slice++) { | ||
| const table = new Array(512); | ||
| for (let i = 0; i < 256; i++) { | ||
| let crc = BigInt(i); | ||
| for (let j = 0; j < 8 * (slice + 1); j++) { | ||
| if (crc & 1n) { | ||
| crc = (crc >> 1n) ^ 0x9a6c9329ac4bc9b5n; | ||
| } | ||
| else { | ||
| crc = crc >> 1n; | ||
| } | ||
| } | ||
| table[i * 2] = Number((crc >> 32n) & 0xffffffffn); | ||
| table[i * 2 + 1] = Number(crc & 0xffffffffn); | ||
| } | ||
| tables[slice] = new Uint32Array(table); | ||
| } | ||
| return tables; | ||
| }; | ||
| let CRC64_NVME_REVERSED_TABLE; | ||
| let t0, t1, t2, t3; | ||
| let t4, t5, t6, t7; | ||
| const ensureTablesInitialized = () => { | ||
| if (!CRC64_NVME_REVERSED_TABLE) { | ||
| CRC64_NVME_REVERSED_TABLE = generateCRC64NVMETable(); | ||
| [t0, t1, t2, t3, t4, t5, t6, t7] = CRC64_NVME_REVERSED_TABLE; | ||
| } | ||
| }; | ||
| export class Crc64Nvme { | ||
| c1 = 0; | ||
| c2 = 0; | ||
| constructor() { | ||
| ensureTablesInitialized(); | ||
| this.reset(); | ||
| } | ||
| update(data) { | ||
| const len = data.length; | ||
| let i = 0; | ||
| let crc1 = this.c1; | ||
| let crc2 = this.c2; | ||
| while (i + 8 <= len) { | ||
| const idx0 = ((crc2 ^ data[i++]) & 255) << 1; | ||
| const idx1 = (((crc2 >>> 8) ^ data[i++]) & 255) << 1; | ||
| const idx2 = (((crc2 >>> 16) ^ data[i++]) & 255) << 1; | ||
| const idx3 = (((crc2 >>> 24) ^ data[i++]) & 255) << 1; | ||
| const idx4 = ((crc1 ^ data[i++]) & 255) << 1; | ||
| const idx5 = (((crc1 >>> 8) ^ data[i++]) & 255) << 1; | ||
| const idx6 = (((crc1 >>> 16) ^ data[i++]) & 255) << 1; | ||
| const idx7 = (((crc1 >>> 24) ^ data[i++]) & 255) << 1; | ||
| crc1 = t7[idx0] ^ t6[idx1] ^ t5[idx2] ^ t4[idx3] ^ t3[idx4] ^ t2[idx5] ^ t1[idx6] ^ t0[idx7]; | ||
| crc2 = | ||
| t7[idx0 + 1] ^ | ||
| t6[idx1 + 1] ^ | ||
| t5[idx2 + 1] ^ | ||
| t4[idx3 + 1] ^ | ||
| t3[idx4 + 1] ^ | ||
| t2[idx5 + 1] ^ | ||
| t1[idx6 + 1] ^ | ||
| t0[idx7 + 1]; | ||
| } | ||
| while (i < len) { | ||
| const idx = ((crc2 ^ data[i]) & 255) << 1; | ||
| crc2 = ((crc2 >>> 8) | ((crc1 & 255) << 24)) >>> 0; | ||
| crc1 = (crc1 >>> 8) ^ t0[idx]; | ||
| crc2 ^= t0[idx + 1]; | ||
| i++; | ||
| } | ||
| this.c1 = crc1; | ||
| this.c2 = crc2; | ||
| } | ||
| async digest() { | ||
| const c1 = this.c1 ^ 4294967295; | ||
| const c2 = this.c2 ^ 4294967295; | ||
| return new Uint8Array([ | ||
| c1 >>> 24, | ||
| (c1 >>> 16) & 255, | ||
| (c1 >>> 8) & 255, | ||
| c1 & 255, | ||
| c2 >>> 24, | ||
| (c2 >>> 16) & 255, | ||
| (c2 >>> 8) & 255, | ||
| c2 & 255, | ||
| ]); | ||
| } | ||
| reset() { | ||
| this.c1 = 4294967295; | ||
| this.c2 = 4294967295; | ||
| } | ||
| } |
| export {}; |
| export const RequestChecksumCalculation = { | ||
| WHEN_SUPPORTED: "WHEN_SUPPORTED", | ||
| WHEN_REQUIRED: "WHEN_REQUIRED", | ||
| }; | ||
| export const DEFAULT_REQUEST_CHECKSUM_CALCULATION = RequestChecksumCalculation.WHEN_SUPPORTED; | ||
| export const ResponseChecksumValidation = { | ||
| WHEN_SUPPORTED: "WHEN_SUPPORTED", | ||
| WHEN_REQUIRED: "WHEN_REQUIRED", | ||
| }; | ||
| export const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.WHEN_SUPPORTED; | ||
| export var ChecksumAlgorithm; | ||
| (function (ChecksumAlgorithm) { | ||
| ChecksumAlgorithm["MD5"] = "MD5"; | ||
| ChecksumAlgorithm["CRC32"] = "CRC32"; | ||
| ChecksumAlgorithm["CRC32C"] = "CRC32C"; | ||
| ChecksumAlgorithm["CRC64NVME"] = "CRC64NVME"; | ||
| ChecksumAlgorithm["SHA1"] = "SHA1"; | ||
| ChecksumAlgorithm["SHA256"] = "SHA256"; | ||
| })(ChecksumAlgorithm || (ChecksumAlgorithm = {})); | ||
| export var ChecksumLocation; | ||
| (function (ChecksumLocation) { | ||
| ChecksumLocation["HEADER"] = "header"; | ||
| ChecksumLocation["TRAILER"] = "trailer"; | ||
| })(ChecksumLocation || (ChecksumLocation = {})); | ||
| export const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; |
| import { setFeature } from "@aws-sdk/core/client"; | ||
| import { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; | ||
| export const flexibleChecksumsInputMiddlewareOptions = { | ||
| name: "flexibleChecksumsInputMiddleware", | ||
| toMiddleware: "serializerMiddleware", | ||
| relation: "before", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| export const flexibleChecksumsInputMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| const input = args.input; | ||
| const { requestValidationModeMember } = middlewareConfig; | ||
| const requestChecksumCalculation = await config.requestChecksumCalculation(); | ||
| const responseChecksumValidation = await config.responseChecksumValidation(); | ||
| switch (requestChecksumCalculation) { | ||
| case RequestChecksumCalculation.WHEN_REQUIRED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED", "a"); | ||
| break; | ||
| case RequestChecksumCalculation.WHEN_SUPPORTED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED", "Z"); | ||
| break; | ||
| } | ||
| switch (responseChecksumValidation) { | ||
| case ResponseChecksumValidation.WHEN_REQUIRED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED", "c"); | ||
| break; | ||
| case ResponseChecksumValidation.WHEN_SUPPORTED: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED", "b"); | ||
| break; | ||
| } | ||
| if (requestValidationModeMember && !input[requestValidationModeMember]) { | ||
| if (responseChecksumValidation === ResponseChecksumValidation.WHEN_SUPPORTED) { | ||
| input[requestValidationModeMember] = "ENABLED"; | ||
| } | ||
| } | ||
| return next(args); | ||
| }; |
| import { setFeature } from "@aws-sdk/core/client"; | ||
| import { HttpRequest } from "@smithy/core/protocols"; | ||
| import { createBufferedReadable } from "@smithy/core/serde"; | ||
| import { ChecksumAlgorithm, DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation } from "./constants"; | ||
| import { getChecksumAlgorithmForRequest } from "./getChecksumAlgorithmForRequest"; | ||
| import { getChecksumLocationName } from "./getChecksumLocationName"; | ||
| import { hasHeader } from "./hasHeader"; | ||
| import { hasHeaderWithPrefix } from "./hasHeaderWithPrefix"; | ||
| import { isStreaming } from "./isStreaming"; | ||
| import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction"; | ||
| import { stringHasher } from "./stringHasher"; | ||
| export const flexibleChecksumsMiddlewareOptions = { | ||
| name: "flexibleChecksumsMiddleware", | ||
| step: "build", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| export const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| if (!HttpRequest.isInstance(args.request)) { | ||
| return next(args); | ||
| } | ||
| if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) { | ||
| return next(args); | ||
| } | ||
| const { request, input } = args; | ||
| const { body: requestBody, headers } = request; | ||
| const { base64Encoder, streamHasher } = config; | ||
| const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; | ||
| const requestChecksumCalculation = await config.requestChecksumCalculation(); | ||
| const requestAlgorithmMemberName = requestAlgorithmMember?.name; | ||
| const requestAlgorithmMemberHttpHeader = requestAlgorithmMember?.httpHeader; | ||
| if (requestAlgorithmMemberName && !input[requestAlgorithmMemberName]) { | ||
| if (requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired) { | ||
| input[requestAlgorithmMemberName] = DEFAULT_CHECKSUM_ALGORITHM; | ||
| if (requestAlgorithmMemberHttpHeader) { | ||
| headers[requestAlgorithmMemberHttpHeader] = DEFAULT_CHECKSUM_ALGORITHM; | ||
| } | ||
| } | ||
| } | ||
| const checksumAlgorithm = getChecksumAlgorithmForRequest(input, { | ||
| requestChecksumRequired, | ||
| requestAlgorithmMember: requestAlgorithmMember?.name, | ||
| requestChecksumCalculation, | ||
| }); | ||
| let updatedBody = requestBody; | ||
| let updatedHeaders = headers; | ||
| if (checksumAlgorithm) { | ||
| switch (checksumAlgorithm) { | ||
| case ChecksumAlgorithm.CRC32: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32", "U"); | ||
| break; | ||
| case ChecksumAlgorithm.CRC32C: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V"); | ||
| break; | ||
| case ChecksumAlgorithm.CRC64NVME: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W"); | ||
| break; | ||
| case ChecksumAlgorithm.SHA1: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X"); | ||
| break; | ||
| case ChecksumAlgorithm.SHA256: | ||
| setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA256", "Y"); | ||
| break; | ||
| } | ||
| const checksumLocationName = getChecksumLocationName(checksumAlgorithm); | ||
| const checksumAlgorithmFn = selectChecksumAlgorithmFunction(checksumAlgorithm, config); | ||
| if (isStreaming(requestBody)) { | ||
| const { getAwsChunkedEncodingStream, bodyLengthChecker } = config; | ||
| updatedBody = getAwsChunkedEncodingStream(typeof config.requestStreamBufferSize === "number" && config.requestStreamBufferSize >= 8 * 1024 | ||
| ? createBufferedReadable(requestBody, config.requestStreamBufferSize, context.logger) | ||
| : requestBody, { | ||
| base64Encoder, | ||
| bodyLengthChecker, | ||
| checksumLocationName, | ||
| checksumAlgorithmFn, | ||
| streamHasher, | ||
| }); | ||
| updatedHeaders = { | ||
| ...headers, | ||
| "content-encoding": headers["content-encoding"] | ||
| ? `${headers["content-encoding"]},aws-chunked` | ||
| : "aws-chunked", | ||
| "transfer-encoding": "chunked", | ||
| "x-amz-decoded-content-length": headers["content-length"], | ||
| "x-amz-content-sha256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER", | ||
| "x-amz-trailer": checksumLocationName, | ||
| }; | ||
| delete updatedHeaders["content-length"]; | ||
| } | ||
| else if (!hasHeader(checksumLocationName, headers)) { | ||
| const rawChecksum = await stringHasher(checksumAlgorithmFn, requestBody); | ||
| updatedHeaders = { | ||
| ...headers, | ||
| [checksumLocationName]: base64Encoder(rawChecksum), | ||
| }; | ||
| } | ||
| } | ||
| try { | ||
| const result = await next({ | ||
| ...args, | ||
| request: { | ||
| ...request, | ||
| headers: updatedHeaders, | ||
| body: updatedBody, | ||
| }, | ||
| }); | ||
| return result; | ||
| } | ||
| catch (e) { | ||
| if (e instanceof Error && e.name === "InvalidChunkSizeError") { | ||
| try { | ||
| if (!e.message.endsWith(".")) { | ||
| e.message += "."; | ||
| } | ||
| e.message += | ||
| " Set [requestStreamBufferSize=number e.g. 65_536] in client constructor to instruct AWS SDK to buffer your input stream."; | ||
| } | ||
| catch (ignored) { | ||
| } | ||
| } | ||
| throw e; | ||
| } | ||
| }; |
| import { HttpRequest } from "@smithy/core/protocols"; | ||
| import { getChecksumAlgorithmListForResponse } from "./getChecksumAlgorithmListForResponse"; | ||
| import { getChecksumLocationName } from "./getChecksumLocationName"; | ||
| import { isChecksumWithPartNumber } from "./isChecksumWithPartNumber"; | ||
| import { validateChecksumFromResponse } from "./validateChecksumFromResponse"; | ||
| export const flexibleChecksumsResponseMiddlewareOptions = { | ||
| name: "flexibleChecksumsResponseMiddleware", | ||
| toMiddleware: "deserializerMiddleware", | ||
| relation: "after", | ||
| tags: ["BODY_CHECKSUM"], | ||
| override: true, | ||
| }; | ||
| export const flexibleChecksumsResponseMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
| if (!HttpRequest.isInstance(args.request)) { | ||
| return next(args); | ||
| } | ||
| const input = args.input; | ||
| const result = await next(args); | ||
| const response = result.response; | ||
| const { requestValidationModeMember, responseAlgorithms } = middlewareConfig; | ||
| if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") { | ||
| const { clientName, commandName } = context; | ||
| const customChecksumAlgorithms = Object.keys(config.checksumAlgorithms ?? {}).filter((algorithm) => { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| return response.headers[responseHeader] !== undefined; | ||
| }); | ||
| const algoList = getChecksumAlgorithmListForResponse([ | ||
| ...(responseAlgorithms ?? []), | ||
| ...customChecksumAlgorithms, | ||
| ]); | ||
| const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" && | ||
| commandName === "GetObjectCommand" && | ||
| algoList.every((algorithm) => { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| const checksumFromResponse = response.headers[responseHeader]; | ||
| return !checksumFromResponse || isChecksumWithPartNumber(checksumFromResponse); | ||
| }); | ||
| if (isS3WholeObjectMultipartGetResponseChecksum) { | ||
| return result; | ||
| } | ||
| await validateChecksumFromResponse(response, { | ||
| config, | ||
| responseAlgorithms: algoList, | ||
| logger: context.logger, | ||
| }); | ||
| } | ||
| return result; | ||
| }; |
| import { stringHasher } from "./stringHasher"; | ||
| export const getChecksum = async (body, { checksumAlgorithmFn, base64Encoder }) => base64Encoder(await stringHasher(checksumAlgorithmFn, body)); |
| import { DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation } from "./constants"; | ||
| export const getChecksumAlgorithmForRequest = (input, { requestChecksumRequired, requestAlgorithmMember, requestChecksumCalculation }) => { | ||
| if (!requestAlgorithmMember) { | ||
| return requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired | ||
| ? DEFAULT_CHECKSUM_ALGORITHM | ||
| : undefined; | ||
| } | ||
| if (!input[requestAlgorithmMember]) { | ||
| return undefined; | ||
| } | ||
| const checksumAlgorithm = input[requestAlgorithmMember]; | ||
| return checksumAlgorithm; | ||
| }; |
| import { PRIORITY_ORDER_ALGORITHMS } from "./types"; | ||
| export const getChecksumAlgorithmListForResponse = (responseAlgorithms = []) => { | ||
| const validChecksumAlgorithms = []; | ||
| let i = PRIORITY_ORDER_ALGORITHMS.length; | ||
| for (const algorithm of responseAlgorithms) { | ||
| const priority = PRIORITY_ORDER_ALGORITHMS.indexOf(algorithm); | ||
| if (priority !== -1) { | ||
| validChecksumAlgorithms[priority] = algorithm; | ||
| } | ||
| else { | ||
| validChecksumAlgorithms[i++] = algorithm; | ||
| } | ||
| } | ||
| return validChecksumAlgorithms.filter(Boolean); | ||
| }; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export const getChecksumLocationName = (algorithm) => algorithm === ChecksumAlgorithm.MD5 ? "content-md5" : `x-amz-checksum-${algorithm.toLowerCase()}`; |
| import { AwsCrc32 } from "@aws-crypto/crc32"; | ||
| export const getCrc32ChecksumAlgorithmFunction = () => AwsCrc32; |
| import { AwsCrc32 } from "@aws-crypto/crc32"; | ||
| import { numToUint8 } from "@aws-crypto/util"; | ||
| import * as zlib from "node:zlib"; | ||
| class NodeCrc32 { | ||
| checksum = 0; | ||
| update(data) { | ||
| this.checksum = zlib.crc32(data, this.checksum); | ||
| } | ||
| async digest() { | ||
| return numToUint8(this.checksum); | ||
| } | ||
| reset() { | ||
| this.checksum = 0; | ||
| } | ||
| } | ||
| export const getCrc32ChecksumAlgorithmFunction = () => { | ||
| if (typeof zlib.crc32 === "undefined") { | ||
| return AwsCrc32; | ||
| } | ||
| return NodeCrc32; | ||
| }; |
| import { flexibleChecksumsInputMiddleware, flexibleChecksumsInputMiddlewareOptions, } from "./flexibleChecksumsInputMiddleware"; | ||
| import { flexibleChecksumsMiddleware, flexibleChecksumsMiddlewareOptions } from "./flexibleChecksumsMiddleware"; | ||
| import { flexibleChecksumsResponseMiddleware, flexibleChecksumsResponseMiddlewareOptions, } from "./flexibleChecksumsResponseMiddleware"; | ||
| export const getFlexibleChecksumsPlugin = (config, middlewareConfig) => ({ | ||
| applyToStack: (clientStack) => { | ||
| clientStack.add(flexibleChecksumsMiddleware(config, middlewareConfig), flexibleChecksumsMiddlewareOptions); | ||
| clientStack.addRelativeTo(flexibleChecksumsInputMiddleware(config, middlewareConfig), flexibleChecksumsInputMiddlewareOptions); | ||
| clientStack.addRelativeTo(flexibleChecksumsResponseMiddleware(config, middlewareConfig), flexibleChecksumsResponseMiddlewareOptions); | ||
| }, | ||
| }); |
| export const hasHeader = (header, headers) => { | ||
| const soughtHeader = header.toLowerCase(); | ||
| for (const headerName of Object.keys(headers)) { | ||
| if (soughtHeader === headerName.toLowerCase()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; |
| export const hasHeaderWithPrefix = (headerPrefix, headers) => { | ||
| const soughtHeaderPrefix = headerPrefix.toLowerCase(); | ||
| for (const headerName of Object.keys(headers)) { | ||
| if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; |
| export const isChecksumWithPartNumber = (checksum) => { | ||
| const lastHyphenIndex = checksum.lastIndexOf("-"); | ||
| if (lastHyphenIndex !== -1) { | ||
| const numberPart = checksum.slice(lastHyphenIndex + 1); | ||
| if (!numberPart.startsWith("0")) { | ||
| const number = parseInt(numberPart, 10); | ||
| if (!isNaN(number) && number >= 1 && number <= 10000) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| }; |
| import { isArrayBuffer } from "@smithy/core/serde"; | ||
| export const isStreaming = (body) => body !== undefined && typeof body !== "string" && !ArrayBuffer.isView(body) && !isArrayBuffer(body); |
| import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation } from "./constants"; | ||
| import { SelectorType, stringUnionSelector } from "./stringUnionSelector"; | ||
| export const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION"; | ||
| export const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation"; | ||
| export const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS = { | ||
| environmentVariableSelector: (env) => stringUnionSelector(env, ENV_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.ENV), | ||
| configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.CONFIG), | ||
| default: DEFAULT_REQUEST_CHECKSUM_CALCULATION, | ||
| }; |
| import { DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation } from "./constants"; | ||
| import { SelectorType, stringUnionSelector } from "./stringUnionSelector"; | ||
| export const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION"; | ||
| export const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation"; | ||
| export const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS = { | ||
| environmentVariableSelector: (env) => stringUnionSelector(env, ENV_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.ENV), | ||
| configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.CONFIG), | ||
| default: DEFAULT_RESPONSE_CHECKSUM_VALIDATION, | ||
| }; |
| import { normalizeProvider } from "@smithy/core/client"; | ||
| import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION } from "./constants"; | ||
| export const resolveFlexibleChecksumsConfig = (input) => { | ||
| const { requestChecksumCalculation, responseChecksumValidation, requestStreamBufferSize } = input; | ||
| return Object.assign(input, { | ||
| requestChecksumCalculation: normalizeProvider(requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION), | ||
| responseChecksumValidation: normalizeProvider(responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION), | ||
| requestStreamBufferSize: Number(requestStreamBufferSize ?? 0), | ||
| checksumAlgorithms: input.checksumAlgorithms ?? {}, | ||
| }); | ||
| }; |
| import { AwsCrc32c } from "@aws-crypto/crc32c"; | ||
| import { crc64NvmeCrtContainer } from "../crc64-nvme/crc64-nvme-crt-container"; | ||
| import { Crc64Nvme } from "../crc64-nvme/Crc64Nvme"; | ||
| import { ChecksumAlgorithm } from "./constants"; | ||
| import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction"; | ||
| import { CLIENT_SUPPORTED_ALGORITHMS } from "./types"; | ||
| export const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => { | ||
| const { checksumAlgorithms = {} } = config; | ||
| switch (checksumAlgorithm) { | ||
| case ChecksumAlgorithm.MD5: | ||
| return checksumAlgorithms?.MD5 ?? config.md5; | ||
| case ChecksumAlgorithm.CRC32: | ||
| return checksumAlgorithms?.CRC32 ?? getCrc32ChecksumAlgorithmFunction(); | ||
| case ChecksumAlgorithm.CRC32C: | ||
| return checksumAlgorithms?.CRC32C ?? AwsCrc32c; | ||
| case ChecksumAlgorithm.CRC64NVME: | ||
| if (typeof crc64NvmeCrtContainer.CrtCrc64Nvme !== "function") { | ||
| return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme; | ||
| } | ||
| return checksumAlgorithms?.CRC64NVME ?? crc64NvmeCrtContainer.CrtCrc64Nvme; | ||
| case ChecksumAlgorithm.SHA1: | ||
| return checksumAlgorithms?.SHA1 ?? config.sha1; | ||
| case ChecksumAlgorithm.SHA256: | ||
| return checksumAlgorithms?.SHA256 ?? config.sha256; | ||
| default: | ||
| if (checksumAlgorithms?.[checksumAlgorithm]) { | ||
| return checksumAlgorithms[checksumAlgorithm]; | ||
| } | ||
| throw new Error(`The checksum algorithm "${checksumAlgorithm}" is not supported by the client.` + | ||
| ` Select one of ${CLIENT_SUPPORTED_ALGORITHMS}, or provide an implementation to ` + | ||
| ` the client constructor checksums field.`); | ||
| } | ||
| }; |
| import { toUint8Array } from "@smithy/core/serde"; | ||
| export const stringHasher = (checksumAlgorithmFn, body) => { | ||
| const hash = new checksumAlgorithmFn(); | ||
| hash.update(toUint8Array(body || "")); | ||
| return hash.digest(); | ||
| }; |
| export var SelectorType; | ||
| (function (SelectorType) { | ||
| SelectorType["ENV"] = "env"; | ||
| SelectorType["CONFIG"] = "shared config entry"; | ||
| })(SelectorType || (SelectorType = {})); | ||
| export const stringUnionSelector = (obj, key, union, type) => { | ||
| if (!(key in obj)) | ||
| return undefined; | ||
| const value = obj[key].toUpperCase(); | ||
| if (!Object.values(union).includes(value)) { | ||
| throw new TypeError(`Cannot load ${type} '${key}'. Expected one of ${Object.values(union)}, got '${obj[key]}'.`); | ||
| } | ||
| return value; | ||
| }; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export const CLIENT_SUPPORTED_ALGORITHMS = [ | ||
| ChecksumAlgorithm.CRC32, | ||
| ChecksumAlgorithm.CRC32C, | ||
| ChecksumAlgorithm.CRC64NVME, | ||
| ChecksumAlgorithm.SHA1, | ||
| ChecksumAlgorithm.SHA256, | ||
| ]; | ||
| export const PRIORITY_ORDER_ALGORITHMS = [ | ||
| ChecksumAlgorithm.SHA256, | ||
| ChecksumAlgorithm.SHA1, | ||
| ChecksumAlgorithm.CRC32, | ||
| ChecksumAlgorithm.CRC32C, | ||
| ChecksumAlgorithm.CRC64NVME, | ||
| ]; |
| import { createChecksumStream } from "@smithy/core/serde"; | ||
| import { ChecksumAlgorithm } from "./constants"; | ||
| import { getChecksum } from "./getChecksum"; | ||
| import { getChecksumAlgorithmListForResponse } from "./getChecksumAlgorithmListForResponse"; | ||
| import { getChecksumLocationName } from "./getChecksumLocationName"; | ||
| import { isStreaming } from "./isStreaming"; | ||
| import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction"; | ||
| export const validateChecksumFromResponse = async (response, { config, responseAlgorithms, logger }) => { | ||
| const checksumAlgorithms = getChecksumAlgorithmListForResponse(responseAlgorithms); | ||
| const { body: responseBody, headers: responseHeaders } = response; | ||
| for (const algorithm of checksumAlgorithms) { | ||
| const responseHeader = getChecksumLocationName(algorithm); | ||
| const checksumFromResponse = responseHeaders[responseHeader]; | ||
| if (checksumFromResponse) { | ||
| let checksumAlgorithmFn; | ||
| try { | ||
| checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config); | ||
| } | ||
| catch (error) { | ||
| if (algorithm === ChecksumAlgorithm.CRC64NVME) { | ||
| logger?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`); | ||
| continue; | ||
| } | ||
| throw error; | ||
| } | ||
| const { base64Encoder } = config; | ||
| if (isStreaming(responseBody)) { | ||
| response.body = createChecksumStream({ | ||
| expectedChecksum: checksumFromResponse, | ||
| checksumSourceLocation: responseHeader, | ||
| checksum: new checksumAlgorithmFn(), | ||
| source: responseBody, | ||
| base64Encoder, | ||
| }); | ||
| return; | ||
| } | ||
| const checksum = await getChecksum(responseBody, { checksumAlgorithmFn, base64Encoder }); | ||
| if (checksum === checksumFromResponse) { | ||
| break; | ||
| } | ||
| throw new Error(`Checksum mismatch: expected "${checksum}" but received "${checksumFromResponse}"` + | ||
| ` in response header "${responseHeader}".`); | ||
| } | ||
| } | ||
| }; |
| import type { ChecksumConstructor } from "@smithy/types"; | ||
| /** | ||
| * @internal | ||
| * | ||
| * \@aws-sdk/crc64-nvme-crt will install the constructor in this | ||
| * container if it is installed. | ||
| * | ||
| * This avoids a runtime-require being interpreted statically by bundlers. | ||
| * | ||
| */ | ||
| export declare const crc64NvmeCrtContainer: { | ||
| CrtCrc64Nvme: null | ChecksumConstructor; | ||
| }; |
| import type { Checksum } from "@smithy/types"; | ||
| /** | ||
| * Implements CRC-64/NVME checksum algorithm. | ||
| * | ||
| * This class provides CRC-64 checksum calculation using the NVMe polynomial (0x9a6c9329ac4bc9b5). | ||
| * It uses an 8-slice lookup table for efficient computation. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const checksum = new Crc64Nvme(); | ||
| * checksum.update(new Uint8Array([1, 2, 3])); | ||
| * const result = await checksum.digest(); | ||
| * ``` | ||
| * | ||
| * @public | ||
| */ | ||
| export declare class Crc64Nvme implements Checksum { | ||
| private c1; | ||
| private c2; | ||
| constructor(); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } |
| import type { BodyLengthCalculator, ChecksumConstructor, Encoder, GetAwsChunkedEncodingStream, HashConstructor, Provider, StreamCollector, StreamHasher } from "@smithy/types"; | ||
| import type { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; | ||
| import type { FlexibleChecksumsInputConfig } from "./resolveFlexibleChecksumsConfig"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface PreviouslyResolved { | ||
| /** | ||
| * The function that will be used to convert binary data to a base64-encoded string. | ||
| * @internal | ||
| */ | ||
| base64Encoder: Encoder; | ||
| /** | ||
| * A function that can calculate the length of a body. | ||
| */ | ||
| bodyLengthChecker: BodyLengthCalculator; | ||
| /** | ||
| * A function that returns Readable Stream which follows aws-chunked encoding stream. | ||
| */ | ||
| getAwsChunkedEncodingStream: GetAwsChunkedEncodingStream; | ||
| /** | ||
| * A constructor for a class implementing the {@link Hash} interface that computes MD5 hashes. | ||
| * @internal | ||
| */ | ||
| md5: ChecksumConstructor | HashConstructor; | ||
| /** | ||
| * Determines when a checksum will be calculated for request payloads | ||
| */ | ||
| requestChecksumCalculation: Provider<RequestChecksumCalculation>; | ||
| /** | ||
| * Determines when a checksum will be calculated for response payloads | ||
| */ | ||
| responseChecksumValidation: Provider<ResponseChecksumValidation>; | ||
| /** | ||
| * A constructor for a class implementing the {@link Hash} interface that computes SHA1 hashes. | ||
| * @internal | ||
| */ | ||
| sha1: ChecksumConstructor | HashConstructor; | ||
| /** | ||
| * A constructor for a class implementing the {@link Hash} interface that computes SHA256 hashes. | ||
| * @internal | ||
| */ | ||
| sha256: ChecksumConstructor | HashConstructor; | ||
| /** | ||
| * A function that, given a hash constructor and a stream, calculates the hash of the streamed value. | ||
| * @internal | ||
| */ | ||
| streamHasher: StreamHasher<any>; | ||
| /** | ||
| * Collects streams into buffers. | ||
| */ | ||
| streamCollector: StreamCollector; | ||
| /** | ||
| * Minimum bytes from a stream to buffer into a chunk before passing to chunked encoding. | ||
| */ | ||
| requestStreamBufferSize: number; | ||
| checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"]; | ||
| } |
| /** | ||
| * Determines when a checksum will be calculated for request payloads. | ||
| * @public | ||
| */ | ||
| export declare const RequestChecksumCalculation: { | ||
| /** | ||
| * When set, a checksum will be calculated for all request payloads of operations | ||
| * modeled with the {@link httpChecksum} trait where `requestChecksumRequired` is `true` | ||
| * AND/OR a `requestAlgorithmMember` is modeled. | ||
| * {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum} | ||
| */ | ||
| readonly WHEN_SUPPORTED: "WHEN_SUPPORTED"; | ||
| /** | ||
| * When set, a checksum will only be calculated for request payloads of operations | ||
| * modeled with the {@link httpChecksum} trait where `requestChecksumRequired` is `true` | ||
| * OR where a `requestAlgorithmMember` is modeled and the user sets it. | ||
| * {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum} | ||
| */ | ||
| readonly WHEN_REQUIRED: "WHEN_REQUIRED"; | ||
| }; | ||
| /** | ||
| * @public | ||
| */ | ||
| export type RequestChecksumCalculation = (typeof RequestChecksumCalculation)[keyof typeof RequestChecksumCalculation]; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const DEFAULT_REQUEST_CHECKSUM_CALCULATION: "WHEN_SUPPORTED"; | ||
| /** | ||
| * Determines when checksum validation will be performed on response payloads. | ||
| * @public | ||
| */ | ||
| export declare const ResponseChecksumValidation: { | ||
| /** | ||
| * When set, checksum validation MUST be performed on all response payloads of operations | ||
| * modeled with the {@link httpChecksum} trait where `responseAlgorithms` is modeled, | ||
| * except when no modeled checksum algorithms are supported by an SDK. | ||
| * {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum} | ||
| */ | ||
| readonly WHEN_SUPPORTED: "WHEN_SUPPORTED"; | ||
| /** | ||
| * When set, checksum validation MUST NOT be performed on response payloads of operations UNLESS | ||
| * the SDK supports the modeled checksum algorithms AND the user has set the `requestValidationModeMember` to `ENABLED`. | ||
| * It is currently impossible to model an operation as requiring a response checksum, | ||
| * but this setting leaves the door open for future updates. | ||
| */ | ||
| readonly WHEN_REQUIRED: "WHEN_REQUIRED"; | ||
| }; | ||
| /** | ||
| * @public | ||
| */ | ||
| export type ResponseChecksumValidation = (typeof ResponseChecksumValidation)[keyof typeof ResponseChecksumValidation]; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const DEFAULT_RESPONSE_CHECKSUM_VALIDATION: "WHEN_SUPPORTED"; | ||
| /** | ||
| * Checksum Algorithms supported by the SDK. | ||
| * @public | ||
| */ | ||
| export declare enum ChecksumAlgorithm { | ||
| /** | ||
| * @deprecated Use {@link ChecksumAlgorithm.CRC32} instead. | ||
| */ | ||
| MD5 = "MD5", | ||
| CRC32 = "CRC32", | ||
| CRC32C = "CRC32C", | ||
| CRC64NVME = "CRC64NVME", | ||
| SHA1 = "SHA1", | ||
| SHA256 = "SHA256" | ||
| } | ||
| /** | ||
| * Location when the checksum is stored in the request body. | ||
| * @internal | ||
| */ | ||
| export declare enum ChecksumLocation { | ||
| HEADER = "header", | ||
| TRAILER = "trailer" | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; |
| import type { RelativeMiddlewareOptions, SerializeMiddleware } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsInputMiddlewareConfig { | ||
| /** | ||
| * Defines a top-level operation input member used to opt-in to best-effort validation | ||
| * of a checksum returned in the HTTP response of the operation. | ||
| */ | ||
| requestValidationModeMember?: string; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const flexibleChecksumsInputMiddlewareOptions: RelativeMiddlewareOptions; | ||
| /** | ||
| * @internal | ||
| * | ||
| * The input counterpart to the flexibleChecksumsMiddleware. | ||
| */ | ||
| export declare const flexibleChecksumsInputMiddleware: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsInputMiddlewareConfig) => SerializeMiddleware<any, any>; |
| import type { BuildHandlerOptions, BuildMiddleware } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsRequestMiddlewareConfig { | ||
| /** | ||
| * Indicates an operation requires a checksum in its HTTP request. | ||
| */ | ||
| requestChecksumRequired: boolean; | ||
| /** | ||
| * Member that is used to configure request checksum behavior. | ||
| */ | ||
| requestAlgorithmMember?: { | ||
| /** | ||
| * Defines a top-level operation input member that is used to configure request checksum behavior. | ||
| */ | ||
| name: string; | ||
| /** | ||
| * The {@link httpHeader} value, if present. | ||
| * {@link https://smithy.io/2.0/spec/http-bindings.html#httpheader-trait httpHeader} | ||
| */ | ||
| httpHeader?: string; | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const flexibleChecksumsMiddlewareOptions: BuildHandlerOptions; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const flexibleChecksumsMiddleware: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsRequestMiddlewareConfig) => BuildMiddleware<any, any>; |
| import type { DeserializeMiddleware, RelativeMiddlewareOptions } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsResponseMiddlewareConfig { | ||
| /** | ||
| * Defines a top-level operation input member used to opt-in to best-effort validation | ||
| * of a checksum returned in the HTTP response of the operation. | ||
| */ | ||
| requestValidationModeMember?: string; | ||
| /** | ||
| * Defines the checksum algorithms clients SHOULD look for when validating checksums | ||
| * returned in the HTTP response. | ||
| */ | ||
| responseAlgorithms?: string[]; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const flexibleChecksumsResponseMiddlewareOptions: RelativeMiddlewareOptions; | ||
| /** | ||
| * @internal | ||
| * | ||
| * The validation counterpart to the flexibleChecksumsMiddleware. | ||
| */ | ||
| export declare const flexibleChecksumsResponseMiddleware: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsResponseMiddlewareConfig) => DeserializeMiddleware<any, any>; |
| import type { ChecksumConstructor, Encoder, HashConstructor } from "@smithy/types"; | ||
| export interface GetChecksumDigestOptions { | ||
| checksumAlgorithmFn: ChecksumConstructor | HashConstructor; | ||
| base64Encoder: Encoder; | ||
| } | ||
| export declare const getChecksum: (body: unknown, { checksumAlgorithmFn, base64Encoder }: GetChecksumDigestOptions) => Promise<string>; |
| import type { ChecksumAlgorithm } from "./constants"; | ||
| import { RequestChecksumCalculation } from "./constants"; | ||
| export interface GetChecksumAlgorithmForRequestOptions { | ||
| /** | ||
| * Indicates an operation requires a checksum in its HTTP request. | ||
| */ | ||
| requestChecksumRequired: boolean; | ||
| /** | ||
| * Defines a top-level operation input member that is used to configure request checksum behavior. | ||
| */ | ||
| requestAlgorithmMember?: string; | ||
| /** | ||
| * Determines when a checksum will be calculated for request payloads | ||
| */ | ||
| requestChecksumCalculation: RequestChecksumCalculation; | ||
| } | ||
| /** | ||
| * Returns the checksum algorithm to use for the request, along with | ||
| * the priority array of location to use to populate checksum and names | ||
| * to be used as a key at the location. | ||
| */ | ||
| export declare const getChecksumAlgorithmForRequest: (input: any, { requestChecksumRequired, requestAlgorithmMember, requestChecksumCalculation }: GetChecksumAlgorithmForRequestOptions) => ChecksumAlgorithm | string | undefined; |
| import type { ChecksumAlgorithm } from "./constants"; | ||
| /** | ||
| * Returns the priority array of algorithm to use to verify checksum and names | ||
| * to be used as a key in the response header. | ||
| */ | ||
| export declare const getChecksumAlgorithmListForResponse: (responseAlgorithms?: string[]) => ChecksumAlgorithm[]; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| /** | ||
| * Returns location (header/trailer) name to use to populate checksum in. | ||
| */ | ||
| export declare const getChecksumLocationName: (algorithm: ChecksumAlgorithm | string) => string; |
| import { AwsCrc32 } from "@aws-crypto/crc32"; | ||
| export declare const getCrc32ChecksumAlgorithmFunction: () => typeof AwsCrc32; |
| import { AwsCrc32 } from "@aws-crypto/crc32"; | ||
| import type { Checksum } from "@smithy/types"; | ||
| declare class NodeCrc32 implements Checksum { | ||
| private checksum; | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } | ||
| export declare const getCrc32ChecksumAlgorithmFunction: () => typeof NodeCrc32 | typeof AwsCrc32; | ||
| export {}; |
| import type { Pluggable } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| import type { FlexibleChecksumsInputMiddlewareConfig } from "./flexibleChecksumsInputMiddleware"; | ||
| import type { FlexibleChecksumsRequestMiddlewareConfig } from "./flexibleChecksumsMiddleware"; | ||
| import type { FlexibleChecksumsResponseMiddlewareConfig } from "./flexibleChecksumsResponseMiddleware"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsMiddlewareConfig extends FlexibleChecksumsRequestMiddlewareConfig, FlexibleChecksumsInputMiddlewareConfig, FlexibleChecksumsResponseMiddlewareConfig { | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const getFlexibleChecksumsPlugin: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsMiddlewareConfig) => Pluggable<any, any>; |
| import type { HeaderBag } from "@smithy/types"; | ||
| /** | ||
| * Returns true if header is present in headers. | ||
| * Comparisons are case-insensitive. | ||
| */ | ||
| export declare const hasHeader: (header: string, headers: HeaderBag) => boolean; |
| import type { HeaderBag } from "@smithy/types"; | ||
| /** | ||
| * Returns true if header with headerPrefix is present in headers. | ||
| * Comparisons are case-insensitive. | ||
| */ | ||
| export declare const hasHeaderWithPrefix: (headerPrefix: string, headers: HeaderBag) => boolean; |
| export declare const isChecksumWithPartNumber: (checksum: string) => boolean; |
| /** | ||
| * Returns true if the given value is a streaming response. | ||
| */ | ||
| export declare const isStreaming: (body: unknown) => boolean; |
| import type { LoadedConfigSelectors } from "@smithy/core/config"; | ||
| import { RequestChecksumCalculation } from "./constants"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS: LoadedConfigSelectors<RequestChecksumCalculation>; |
| import type { LoadedConfigSelectors } from "@smithy/core/config"; | ||
| import { ResponseChecksumValidation } from "./constants"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation"; | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS: LoadedConfigSelectors<ResponseChecksumValidation>; |
| import type { ChecksumConstructor, Provider } from "@smithy/types"; | ||
| import type { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface FlexibleChecksumsInputConfig { | ||
| /** | ||
| * Determines when a checksum will be calculated for request payloads. | ||
| */ | ||
| requestChecksumCalculation?: RequestChecksumCalculation | Provider<RequestChecksumCalculation>; | ||
| /** | ||
| * Determines when checksum validation will be performed on response payloads. | ||
| */ | ||
| responseChecksumValidation?: ResponseChecksumValidation | Provider<ResponseChecksumValidation>; | ||
| /** | ||
| * Default 0 (off). | ||
| * | ||
| * When set to a value greater than or equal to 8192, sets the minimum number | ||
| * of bytes to buffer into a chunk when processing input streams | ||
| * with chunked encoding (that is, when request checksums are enabled). | ||
| * A minimum of 8kb = 8 * 1024 is required, and 64kb or higher is recommended. | ||
| * | ||
| * See https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html. | ||
| * | ||
| * This has a slight performance penalty because it must wrap and buffer | ||
| * your input stream. | ||
| * You do not need to set this value if your stream already flows chunks | ||
| * of 8kb or greater. | ||
| */ | ||
| requestStreamBufferSize?: number | false; | ||
| /** | ||
| * Optional implementations of checksum algorithms adhering to the | ||
| * Checksum interface. | ||
| */ | ||
| checksumAlgorithms?: { | ||
| CRC32?: ChecksumConstructor; | ||
| CRC32C?: ChecksumConstructor; | ||
| CRC64NVME?: ChecksumConstructor; | ||
| SHA1?: ChecksumConstructor; | ||
| SHA256?: ChecksumConstructor; | ||
| } & { | ||
| [algorithmId: string]: ChecksumConstructor; | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export interface FlexibleChecksumsResolvedConfig { | ||
| requestChecksumCalculation: Provider<RequestChecksumCalculation>; | ||
| responseChecksumValidation: Provider<ResponseChecksumValidation>; | ||
| requestStreamBufferSize: number; | ||
| checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"]; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| export declare const resolveFlexibleChecksumsConfig: <T>(input: T & FlexibleChecksumsInputConfig) => T & FlexibleChecksumsResolvedConfig; |
| import type { ChecksumConstructor, HashConstructor } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| import { ChecksumAlgorithm } from "./constants"; | ||
| /** | ||
| * Returns the function that will compute the checksum for the given {@link ChecksumAlgorithm}. | ||
| */ | ||
| export declare const selectChecksumAlgorithmFunction: (checksumAlgorithm: ChecksumAlgorithm | string, config: PreviouslyResolved) => ChecksumConstructor | HashConstructor; |
| import type { ChecksumConstructor, HashConstructor } from "@smithy/types"; | ||
| /** | ||
| * A function that, given a hash constructor and a string, calculates the hash of the string. | ||
| */ | ||
| export declare const stringHasher: (checksumAlgorithmFn: ChecksumConstructor | HashConstructor, body: any) => Promise<Uint8Array>; |
| export declare enum SelectorType { | ||
| ENV = "env", | ||
| CONFIG = "shared config entry" | ||
| } | ||
| /** | ||
| * Returns undefined, if obj[key] is not defined. | ||
| * Returns string value, if the string is defined in obj[key] and it's uppercase matches union value. | ||
| * Throws error for all other cases. | ||
| * | ||
| * @internal | ||
| */ | ||
| export declare const stringUnionSelector: <U extends object, K extends keyof U>(obj: Record<string, string | undefined>, key: string, union: U, type: SelectorType) => U[K] | undefined; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| /** | ||
| * List of algorithms supported by client. | ||
| */ | ||
| export declare const CLIENT_SUPPORTED_ALGORITHMS: ChecksumAlgorithm[]; | ||
| /** | ||
| * Priority order for validating checksum algorithm. A faster algorithm has higher priority. | ||
| */ | ||
| export declare const PRIORITY_ORDER_ALGORITHMS: ChecksumAlgorithm[]; |
| import type { HttpResponse } from "@smithy/core/protocols"; | ||
| import type { Logger } from "@smithy/types"; | ||
| import type { PreviouslyResolved } from "./configuration"; | ||
| export interface ValidateChecksumFromResponseOptions { | ||
| config: PreviouslyResolved; | ||
| /** | ||
| * Defines the checksum algorithms clients SHOULD look for when validating checksums | ||
| * returned in the HTTP response. | ||
| */ | ||
| responseAlgorithms?: string[]; | ||
| logger?: Logger; | ||
| } | ||
| export declare const validateChecksumFromResponse: (response: HttpResponse, { config, responseAlgorithms, logger }: ValidateChecksumFromResponseOptions) => Promise<void>; |
| import { ChecksumConstructor } from "@smithy/types"; | ||
| export declare const crc64NvmeCrtContainer: { | ||
| CrtCrc64Nvme: null | ChecksumConstructor; | ||
| }; |
| import { Checksum } from "@smithy/types"; | ||
| export declare class Crc64Nvme implements Checksum { | ||
| private c1; | ||
| private c2; | ||
| constructor(); | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } |
| import { | ||
| BodyLengthCalculator, | ||
| ChecksumConstructor, | ||
| Encoder, | ||
| GetAwsChunkedEncodingStream, | ||
| HashConstructor, | ||
| Provider, | ||
| StreamCollector, | ||
| StreamHasher, | ||
| } from "@smithy/types"; | ||
| import { | ||
| RequestChecksumCalculation, | ||
| ResponseChecksumValidation, | ||
| } from "./constants"; | ||
| import { FlexibleChecksumsInputConfig } from "./resolveFlexibleChecksumsConfig"; | ||
| export interface PreviouslyResolved { | ||
| base64Encoder: Encoder; | ||
| bodyLengthChecker: BodyLengthCalculator; | ||
| getAwsChunkedEncodingStream: GetAwsChunkedEncodingStream; | ||
| md5: ChecksumConstructor | HashConstructor; | ||
| requestChecksumCalculation: Provider<RequestChecksumCalculation>; | ||
| responseChecksumValidation: Provider<ResponseChecksumValidation>; | ||
| sha1: ChecksumConstructor | HashConstructor; | ||
| sha256: ChecksumConstructor | HashConstructor; | ||
| streamHasher: StreamHasher<any>; | ||
| streamCollector: StreamCollector; | ||
| requestStreamBufferSize: number; | ||
| checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"]; | ||
| } |
| export declare const RequestChecksumCalculation: { | ||
| readonly WHEN_SUPPORTED: "WHEN_SUPPORTED"; | ||
| readonly WHEN_REQUIRED: "WHEN_REQUIRED"; | ||
| }; | ||
| export type RequestChecksumCalculation = | ||
| (typeof RequestChecksumCalculation)[keyof typeof RequestChecksumCalculation]; | ||
| export declare const DEFAULT_REQUEST_CHECKSUM_CALCULATION: "WHEN_SUPPORTED"; | ||
| export declare const ResponseChecksumValidation: { | ||
| readonly WHEN_SUPPORTED: "WHEN_SUPPORTED"; | ||
| readonly WHEN_REQUIRED: "WHEN_REQUIRED"; | ||
| }; | ||
| export type ResponseChecksumValidation = | ||
| (typeof ResponseChecksumValidation)[keyof typeof ResponseChecksumValidation]; | ||
| export declare const DEFAULT_RESPONSE_CHECKSUM_VALIDATION: "WHEN_SUPPORTED"; | ||
| export declare enum ChecksumAlgorithm { | ||
| MD5 = "MD5", | ||
| CRC32 = "CRC32", | ||
| CRC32C = "CRC32C", | ||
| CRC64NVME = "CRC64NVME", | ||
| SHA1 = "SHA1", | ||
| SHA256 = "SHA256", | ||
| } | ||
| export declare enum ChecksumLocation { | ||
| HEADER = "header", | ||
| TRAILER = "trailer", | ||
| } | ||
| export declare const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; |
| import { RelativeMiddlewareOptions, SerializeMiddleware } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| export interface FlexibleChecksumsInputMiddlewareConfig { | ||
| requestValidationModeMember?: string; | ||
| } | ||
| export declare const flexibleChecksumsInputMiddlewareOptions: RelativeMiddlewareOptions; | ||
| export declare const flexibleChecksumsInputMiddleware: ( | ||
| config: PreviouslyResolved, | ||
| middlewareConfig: FlexibleChecksumsInputMiddlewareConfig | ||
| ) => SerializeMiddleware<any, any>; |
| import { BuildHandlerOptions, BuildMiddleware } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| export interface FlexibleChecksumsRequestMiddlewareConfig { | ||
| requestChecksumRequired: boolean; | ||
| requestAlgorithmMember?: { | ||
| name: string; | ||
| httpHeader?: string; | ||
| }; | ||
| } | ||
| export declare const flexibleChecksumsMiddlewareOptions: BuildHandlerOptions; | ||
| export declare const flexibleChecksumsMiddleware: ( | ||
| config: PreviouslyResolved, | ||
| middlewareConfig: FlexibleChecksumsRequestMiddlewareConfig | ||
| ) => BuildMiddleware<any, any>; |
| import { | ||
| DeserializeMiddleware, | ||
| RelativeMiddlewareOptions, | ||
| } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| export interface FlexibleChecksumsResponseMiddlewareConfig { | ||
| requestValidationModeMember?: string; | ||
| responseAlgorithms?: string[]; | ||
| } | ||
| export declare const flexibleChecksumsResponseMiddlewareOptions: RelativeMiddlewareOptions; | ||
| export declare const flexibleChecksumsResponseMiddleware: ( | ||
| config: PreviouslyResolved, | ||
| middlewareConfig: FlexibleChecksumsResponseMiddlewareConfig | ||
| ) => DeserializeMiddleware<any, any>; |
| import { ChecksumConstructor, Encoder, HashConstructor } from "@smithy/types"; | ||
| export interface GetChecksumDigestOptions { | ||
| checksumAlgorithmFn: ChecksumConstructor | HashConstructor; | ||
| base64Encoder: Encoder; | ||
| } | ||
| export declare const getChecksum: ( | ||
| body: unknown, | ||
| { checksumAlgorithmFn, base64Encoder }: GetChecksumDigestOptions | ||
| ) => Promise<string>; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| import { RequestChecksumCalculation } from "./constants"; | ||
| export interface GetChecksumAlgorithmForRequestOptions { | ||
| requestChecksumRequired: boolean; | ||
| requestAlgorithmMember?: string; | ||
| requestChecksumCalculation: RequestChecksumCalculation; | ||
| } | ||
| export declare const getChecksumAlgorithmForRequest: ( | ||
| input: any, | ||
| { | ||
| requestChecksumRequired, | ||
| requestAlgorithmMember, | ||
| requestChecksumCalculation, | ||
| }: GetChecksumAlgorithmForRequestOptions | ||
| ) => ChecksumAlgorithm | string | undefined; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export declare const getChecksumAlgorithmListForResponse: ( | ||
| responseAlgorithms?: string[] | ||
| ) => ChecksumAlgorithm[]; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export declare const getChecksumLocationName: ( | ||
| algorithm: ChecksumAlgorithm | string | ||
| ) => string; |
| import { AwsCrc32 } from "@aws-crypto/crc32"; | ||
| export declare const getCrc32ChecksumAlgorithmFunction: () => typeof AwsCrc32; |
| import { AwsCrc32 } from "@aws-crypto/crc32"; | ||
| import { Checksum } from "@smithy/types"; | ||
| declare class NodeCrc32 implements Checksum { | ||
| private checksum; | ||
| update(data: Uint8Array): void; | ||
| digest(): Promise<Uint8Array>; | ||
| reset(): void; | ||
| } | ||
| export declare const getCrc32ChecksumAlgorithmFunction: () => | ||
| | typeof NodeCrc32 | ||
| | typeof AwsCrc32; | ||
| export {}; |
| import { Pluggable } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| import { FlexibleChecksumsInputMiddlewareConfig } from "./flexibleChecksumsInputMiddleware"; | ||
| import { FlexibleChecksumsRequestMiddlewareConfig } from "./flexibleChecksumsMiddleware"; | ||
| import { FlexibleChecksumsResponseMiddlewareConfig } from "./flexibleChecksumsResponseMiddleware"; | ||
| export interface FlexibleChecksumsMiddlewareConfig | ||
| extends FlexibleChecksumsRequestMiddlewareConfig, | ||
| FlexibleChecksumsInputMiddlewareConfig, | ||
| FlexibleChecksumsResponseMiddlewareConfig {} | ||
| export declare const getFlexibleChecksumsPlugin: ( | ||
| config: PreviouslyResolved, | ||
| middlewareConfig: FlexibleChecksumsMiddlewareConfig | ||
| ) => Pluggable<any, any>; |
| import { HeaderBag } from "@smithy/types"; | ||
| export declare const hasHeader: (header: string, headers: HeaderBag) => boolean; |
| import { HeaderBag } from "@smithy/types"; | ||
| export declare const hasHeaderWithPrefix: ( | ||
| headerPrefix: string, | ||
| headers: HeaderBag | ||
| ) => boolean; |
| export declare const isChecksumWithPartNumber: (checksum: string) => boolean; |
| export declare const isStreaming: (body: unknown) => boolean; |
| import { LoadedConfigSelectors } from "@smithy/core/config"; | ||
| import { RequestChecksumCalculation } from "./constants"; | ||
| export declare const ENV_REQUEST_CHECKSUM_CALCULATION = | ||
| "AWS_REQUEST_CHECKSUM_CALCULATION"; | ||
| export declare const CONFIG_REQUEST_CHECKSUM_CALCULATION = | ||
| "request_checksum_calculation"; | ||
| export declare const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS: LoadedConfigSelectors<RequestChecksumCalculation>; |
| import { LoadedConfigSelectors } from "@smithy/core/config"; | ||
| import { ResponseChecksumValidation } from "./constants"; | ||
| export declare const ENV_RESPONSE_CHECKSUM_VALIDATION = | ||
| "AWS_RESPONSE_CHECKSUM_VALIDATION"; | ||
| export declare const CONFIG_RESPONSE_CHECKSUM_VALIDATION = | ||
| "response_checksum_validation"; | ||
| export declare const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS: LoadedConfigSelectors<ResponseChecksumValidation>; |
| import { ChecksumConstructor, Provider } from "@smithy/types"; | ||
| import { | ||
| RequestChecksumCalculation, | ||
| ResponseChecksumValidation, | ||
| } from "./constants"; | ||
| export interface FlexibleChecksumsInputConfig { | ||
| requestChecksumCalculation?: | ||
| | RequestChecksumCalculation | ||
| | Provider<RequestChecksumCalculation>; | ||
| responseChecksumValidation?: | ||
| | ResponseChecksumValidation | ||
| | Provider<ResponseChecksumValidation>; | ||
| requestStreamBufferSize?: number | false; | ||
| checksumAlgorithms?: { | ||
| CRC32?: ChecksumConstructor; | ||
| CRC32C?: ChecksumConstructor; | ||
| CRC64NVME?: ChecksumConstructor; | ||
| SHA1?: ChecksumConstructor; | ||
| SHA256?: ChecksumConstructor; | ||
| } & { | ||
| [algorithmId: string]: ChecksumConstructor; | ||
| }; | ||
| } | ||
| export interface FlexibleChecksumsResolvedConfig { | ||
| requestChecksumCalculation: Provider<RequestChecksumCalculation>; | ||
| responseChecksumValidation: Provider<ResponseChecksumValidation>; | ||
| requestStreamBufferSize: number; | ||
| checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"]; | ||
| } | ||
| export declare const resolveFlexibleChecksumsConfig: <T>( | ||
| input: T & FlexibleChecksumsInputConfig | ||
| ) => T & FlexibleChecksumsResolvedConfig; |
| import { ChecksumConstructor, HashConstructor } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| import { ChecksumAlgorithm } from "./constants"; | ||
| export declare const selectChecksumAlgorithmFunction: ( | ||
| checksumAlgorithm: ChecksumAlgorithm | string, | ||
| config: PreviouslyResolved | ||
| ) => ChecksumConstructor | HashConstructor; |
| import { ChecksumConstructor, HashConstructor } from "@smithy/types"; | ||
| export declare const stringHasher: ( | ||
| checksumAlgorithmFn: ChecksumConstructor | HashConstructor, | ||
| body: any | ||
| ) => Promise<Uint8Array>; |
| export declare enum SelectorType { | ||
| ENV = "env", | ||
| CONFIG = "shared config entry", | ||
| } | ||
| export declare const stringUnionSelector: <U extends object, K extends keyof U>( | ||
| obj: Record<string, string | undefined>, | ||
| key: string, | ||
| union: U, | ||
| type: SelectorType | ||
| ) => U[K] | undefined; |
| import { ChecksumAlgorithm } from "./constants"; | ||
| export declare const CLIENT_SUPPORTED_ALGORITHMS: ChecksumAlgorithm[]; | ||
| export declare const PRIORITY_ORDER_ALGORITHMS: ChecksumAlgorithm[]; |
| import { HttpResponse } from "@smithy/core/protocols"; | ||
| import { Logger } from "@smithy/types"; | ||
| import { PreviouslyResolved } from "./configuration"; | ||
| export interface ValidateChecksumFromResponseOptions { | ||
| config: PreviouslyResolved; | ||
| responseAlgorithms?: string[]; | ||
| logger?: Logger; | ||
| } | ||
| export declare const validateChecksumFromResponse: ( | ||
| response: HttpResponse, | ||
| { config, responseAlgorithms, logger }: ValidateChecksumFromResponseOptions | ||
| ) => Promise<void>; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
132175
37.58%5
-37.5%127
49.41%2858
50.82%1
Infinity%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated