decode method

Map<String, String>? decode(
  1. String data
)
override

Decodes data into Map

Implementation

Map<String, String>? decode(String data) {
  if (signer != null) {
    List<String> parts = data.split('.');
    if (parts.length != 2) return null;

    try {
      if (base64Url.encode(signer!.convert(parts[0].codeUnits).bytes) !=
          parts[1]) return null;
    } catch (e) {
      return null;
    }

    data = parts[0];
  }

  try {
    String value = String.fromCharCodes(base64Url.decode(data));
    if (encrypter != null) value = encrypter!.decode(value);
    Map values = json.decode(value);
    return values.cast<String, String>();
  } catch (e) {
    return null;
  }
}