From fc4da30933cf790e677a9243167a8ab8c1b92ab2 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Mon, 22 May 2017 15:28:42 +0200 Subject: [PATCH] compute sha256 hash of published assets --- build/tfs/common/publish.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/build/tfs/common/publish.ts b/build/tfs/common/publish.ts index d7a31ce7440..79dba115e40 100644 --- a/build/tfs/common/publish.ts +++ b/build/tfs/common/publish.ts @@ -7,6 +7,7 @@ import * as fs from 'fs'; import { execSync } from 'child_process'; +import { Readable } from 'stream'; import * as crypto from 'crypto'; import * as azure from 'azure-storage'; import * as mime from 'mime'; @@ -18,10 +19,9 @@ if (process.argv.length < 6) { process.exit(-1); } -function sha1hash(file: string): Promise { +function hashStream(hashName: string, stream: Readable): Promise { return new Promise((c, e) => { - const shasum = crypto.createHash('sha1'); - const stream = fs.createReadStream(file); + const shasum = crypto.createHash(hashName); stream .on('data', shasum.update.bind(shasum)) @@ -67,6 +67,7 @@ interface Asset { url: string; mooncakeUrl: string; hash: string; + sha256hash: string; } function createOrUpdate(commit: string, quality: string, platform: string, type: string, release: NewDocument, asset: Asset, isUpdate: boolean): Promise { @@ -162,8 +163,11 @@ async function publish(commit: string, quality: string, platform: string, type: console.log('Is Released:', isReleased); console.log('File:', file); - const hash = await sha1hash(file); - console.log('Hash:', hash); + const stream = fs.createReadStream(file); + const [sha1hash, sha256hash] = await Promise.all([hashStream('sha1', stream), hashStream('sha256', stream)]); + + console.log('SHA1:', sha1hash); + console.log('SHA256:', sha1hash); const blobName = commit + '/' + name; const storageAccount = process.env['AZURE_STORAGE_ACCOUNT_2']; @@ -207,7 +211,8 @@ async function publish(commit: string, quality: string, platform: string, type: type: type, url: `${process.env['AZURE_CDN_URL']}/${quality}/${blobName}`, mooncakeUrl: `${process.env['MOONCAKE_CDN_URL']}/${quality}/${blobName}`, - hash: hash + hash: sha1hash, + sha256hash }; const release = { -- GitLab