decodeShareCode function

SharePayload? decodeShareCode(
  1. String input
)

Decodes a share code, or null when it is malformed or fails the CRC. Callers must still check the family id and that SharePayload. engineVersion is not newer than the app's ("update the app to open this theme").

Implementation

SharePayload? decodeShareCode(String input) {
  final s = normalizeShareCode(input);
  if (s == null) return null;
  final bits = <int>[];
  for (final unit in s.codeUnits) {
    _pushBits(bits, crockfordAlphabet.indexOf(String.fromCharCode(unit)), 5);
  }
  if (crc7(bits.sublist(0, 43)) != _readBits(bits, 43, 7)) return null;
  return SharePayload(
    familyId: _readBits(bits, 0, 5),
    engineVersion: _readBits(bits, 5, 6),
    seed: _readBits(bits, 11, 32),
  );
}