From 3f95e2ea4fe0dd73aaebdcd0f81fbc6fef7d2c4e Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Tue, 26 Apr 2022 22:59:56 +0000 Subject: [PATCH] crc: update headers & digest stream --- packages/artifact/__tests__/util.test.ts | 6 ++---- packages/artifact/src/internal/utils.ts | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/artifact/__tests__/util.test.ts b/packages/artifact/__tests__/util.test.ts index 73e3c78c..22af6781 100644 --- a/packages/artifact/__tests__/util.test.ts +++ b/packages/artifact/__tests__/util.test.ts @@ -97,7 +97,7 @@ describe('Utils', () => { expect(headers['x-tfs-filelength']).toEqual(uncompressedLength) expect(headers['Content-Length']).toEqual(size) expect(headers['Content-Range']).toEqual(range) - expect(headers['X-Digest']).toEqual(`sha-256=${digest}`) + expect(headers['X-GH-Actions-CRC64']).toEqual(digest) }) it('Test constructing upload headers with only required parameter', () => { @@ -230,8 +230,6 @@ describe('Utils', () => { const stream = Readable.from(data) const digest = await utils.digestForStream(stream) - expect(digest).toBe( - '5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269' - ) + expect(digest).toBe('FFFCD6894DC82C6D') }) }) diff --git a/packages/artifact/src/internal/utils.ts b/packages/artifact/src/internal/utils.ts index e23056f6..46f3f245 100644 --- a/packages/artifact/src/internal/utils.ts +++ b/packages/artifact/src/internal/utils.ts @@ -1,4 +1,3 @@ -import * as crypto from 'crypto' import {promises as fs} from 'fs' import {IncomingHttpHeaders} from 'http' import {debug, info, warning} from '@actions/core' @@ -12,6 +11,7 @@ import { getRetryMultiplier, getInitialRetryIntervalInMilliseconds } from './config-variables' +import CRC64 from './crc64' /** * Returns a retry time in milliseconds that exponentially gets larger @@ -205,8 +205,7 @@ export function getUploadHeaders( requestOptions['Content-Range'] = contentRange } if (digest) { - // TODO(robherley): should we use 'Digest' directly? https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Digest - requestOptions['X-Digest'] = `sha-256=${digest}` + requestOptions['X-GH-Actions-CRC64'] = digest } return requestOptions @@ -302,10 +301,9 @@ export async function digestForStream( stream: NodeJS.ReadableStream ): Promise { return new Promise((resolve, reject) => { - // TODO(robherley): switch to crc64 for production - const hasher = crypto.createHash('sha256') + const hasher = new CRC64() stream.on('data', data => hasher.update(data)) - stream.on('end', () => resolve(hasher.digest('hex'))) + stream.on('end', () => resolve(hasher.digest())) stream.on('error', reject) }) }