fromBytes static method
Parses bytes to a PkPass instance.
Setting skipChecksumVerification
to true disables any checksum
verification and validation.
Setting skipSignatureVerification
to true disables any signature
verification and validation. This may be needed for older passes which are
signed with an out of date Apple WWDR
certificate.
Implementation
// TODO(any): Provide an async method for this.
static PkPass fromBytes(
final Uint8List bytes, {
bool skipChecksumVerification = false,
bool skipSignatureVerification = false,
}) {
if (bytes.isEmpty) {
throw EmptyBytesException();
}
ZipDecoder decoder = ZipDecoder();
final archive = decoder.decodeBytes(bytes);
final manifest = archive.readManifest();
final passData = archive.readPass();
if (!skipChecksumVerification) {
archive.checkSha1Checksums(manifest);
if (!skipSignatureVerification) {
final manifestContent =
archive.findFile('manifest.json')!.binaryContent;
final signatureContent = archive.findFile('signature')!.binaryContent;
if (!verifySignature(
signatureBytes: signatureContent,
manifestBytes: manifestContent,
teamIdentifier: passData.teamIdentifier,
identifier: passData.passTypeIdentifier,
)) {
throw Exception('validation failed');
}
}
}
return PkPass(
// data
pass: passData,
manifest: manifest,
personalization: archive.readPersonalization(),
languageData: archive.getTranslations(),
// images
// TODO(ueman): Images can be localized, too
// Maybe it's better to have an on-demand API, something like
// PkPass().getLogo(resolution: 3, languageCode: 'en_EN').
logo: archive.loadImage('logo'),
icon: archive.loadImage('icon'),
footer: archive.loadImage('footer'),
thumbnail: archive.loadImage('thumbnail'),
strip: archive.loadImage('strip'),
background: archive.loadImage('background'),
personalizationLogo: archive.loadImage('personalizationLogo'),
// source
sourceData: bytes,
);
}