mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 13:25:19 +00:00
Locked certificates under a symbol with a setter to validate them first
This commit is contained in:
@@ -18,9 +18,10 @@ const importMetadataSymbol = Symbol("import.pass.metadata");
|
||||
const createManifestSymbol = Symbol("pass.manifest");
|
||||
const closePassSymbol = Symbol("pass.close");
|
||||
const passTypeSymbol = Symbol("pass.type");
|
||||
const certificatesSymbol = Symbol("pass.certificates");
|
||||
|
||||
export default class PKPass extends Bundle {
|
||||
private certificates: Schemas.CertificatesSchema;
|
||||
private [certificatesSymbol]: Schemas.CertificatesSchema;
|
||||
private [fieldKeysPoolSymbol] = new Set<string>();
|
||||
private [propsSymbol]: Schemas.PassProps = {};
|
||||
private [localizationSymbol]: {
|
||||
@@ -56,7 +57,7 @@ export default class PKPass extends Bundle {
|
||||
|
||||
if (source instanceof PKPass) {
|
||||
/** Cloning is happening here */
|
||||
certificates = source.certificates;
|
||||
certificates = source[certificatesSymbol];
|
||||
buffers = {};
|
||||
|
||||
const buffersEntries = Object.entries(source[filesSymbol]);
|
||||
@@ -167,10 +168,26 @@ export default class PKPass extends Bundle {
|
||||
);
|
||||
|
||||
Object.assign(this[propsSymbol], overridesValidation);
|
||||
|
||||
this.certificates = certificates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows changing the certificates, if needed.
|
||||
* They are actually expected to be received in
|
||||
* the constructor, but they can get overridden
|
||||
* here for whatever purpose.
|
||||
*
|
||||
* @param certs
|
||||
*/
|
||||
|
||||
public set certificates(certs: Schemas.CertificatesSchema) {
|
||||
if (!Schemas.isValid(certs, Schemas.CertificatesSchema)) {
|
||||
throw new TypeError("Cannot set certificates: invalid");
|
||||
}
|
||||
|
||||
this[certificatesSymbol] = certs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows getting an image of the props
|
||||
* that are composing your pass instance.
|
||||
@@ -585,7 +602,7 @@ export default class PKPass extends Bundle {
|
||||
|
||||
const signatureBuffer = Signature.create(
|
||||
manifestBuffer,
|
||||
this.certificates,
|
||||
this[certificatesSymbol],
|
||||
);
|
||||
super.addBuffer("signature", signatureBuffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user