Differential updates

This commit is contained in:
Fedor Indutny 2022-02-24 13:01:41 -08:00 committed by GitHub
parent c11e9350d5
commit f58d1332c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 873 additions and 153 deletions

45
ts/updater/util.ts Normal file
View file

@ -0,0 +1,45 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createReadStream } from 'fs';
import { createHash } from 'crypto';
import * as Errors from '../types/errors';
export type CheckIntegrityResultType = Readonly<
| {
ok: true;
error?: void;
}
| {
ok: false;
error: string;
}
>;
export async function checkIntegrity(
fileName: string,
sha512: string
): Promise<CheckIntegrityResultType> {
try {
const hash = createHash('sha512');
for await (const chunk of createReadStream(fileName)) {
hash.update(chunk);
}
const actualSHA512 = hash.digest('base64');
if (sha512 === actualSHA512) {
return { ok: true };
}
return {
ok: false,
error: `Integrity check failure: expected ${sha512}, got ${actualSHA512}`,
};
} catch (error) {
return {
ok: false,
error: Errors.toLogFormat(error),
};
}
}