Moved manifest hashes generation to signature file

This commit is contained in:
Alexander Cerutti
2021-10-03 22:07:41 +02:00
parent f70257dca6
commit c9fb1e7090
2 changed files with 20 additions and 10 deletions

View File

@@ -4,7 +4,6 @@ import { getModelFolderContents } from "./parser";
import * as Schemas from "./schemas";
import { Stream } from "stream";
import { processDate } from "./processDate";
import forge from "node-forge";
import * as Signature from "./signature";
import * as Strings from "./StringsUtils";
import { isValidRGB } from "./utils";
@@ -513,16 +512,13 @@ export default class PKPass extends Bundle {
private [createManifestSymbol](): Buffer {
const manifest = Object.entries(this[filesSymbol]).reduce<{
[key: string]: string;
}>((acc, [fileName, buffer]) => {
const hashFlow = forge.md.sha1.create();
hashFlow.update(buffer.toString("binary"));
return {
}>(
(acc, [fileName, buffer]) => ({
...acc,
[fileName]: hashFlow.digest().toHex(),
};
}, {});
[fileName]: Signature.createHash(buffer),
}),
{},
);
return Buffer.from(JSON.stringify(manifest));
}

View File

@@ -1,6 +1,20 @@
import forge from "node-forge";
import type * as Schemas from "./schemas";
/**
* Creates an hash for a buffer. Used by manifest
*
* @param buffer
* @returns
*/
export function createHash(buffer: Buffer) {
const hashFlow = forge.md.sha1.create();
hashFlow.update(buffer.toString("binary"));
return hashFlow.digest().toHex();
}
/**
* Generates the PKCS #7 cryptografic signature for the manifest file.
*