parseSymmetricPortablePackJson function

SymmetricPortablePack parseSymmetricPortablePackJson(
  1. List<int> data
)

Implementation

SymmetricPortablePack parseSymmetricPortablePackJson(List<int> data) {
  final text = LockEncoding.utf8String(data);
  Map<String, dynamic> json;
  try {
    json = jsonDecode(text) as Map<String, dynamic>;
  } catch (_) {
    raiseInvalidEnvelope('Symmetric portable pack is not valid JSON.');
  }
  if (json['format'] != symmetricPortablePackFormat) {
    raiseInvalidEnvelope('Unexpected symmetric portable pack format.');
  }
  final version = json['version'];
  if (version is! num || version.toInt() != symmetricPortablePackVersion) {
    raiseInvalidEnvelope('Unsupported symmetric portable pack version: $version');
  }
  final envelopeValue = json['envelope'];
  if (envelopeValue is! Map<String, dynamic>) {
    raiseInvalidEnvelope('Symmetric portable pack envelope was not provided.');
  }
  final envelopeBytes = LockEncoding.utf8Bytes(jsonEncode(envelopeValue));
  return SymmetricPortablePack(
    platform: json['platform'] as String? ?? '',
    createdUtc: json['createdUtc'] as String? ?? '',
    envelope: parseSymmetricEnvelopeJson(envelopeBytes),
  );
}