fromJson static method

Future<ScpResponseSetWifiConfig> fromJson(
  1. dynamic inputJson,
  2. String password
)

Implementation

static Future<ScpResponseSetWifiConfig> fromJson(var inputJson, String password) async {
  if (!InputValidation.validateJsonResponse(inputJson)) {
    return ScpResponseSetWifiConfig();
  }
  String response = inputJson['response'];
  String hmac = inputJson['hmac'];

  // Check hmac before additional processing
  if (await ScpCrypto().verifyHMAC(response, hmac, password)) {
    var decodedPayload = base64Decode(response);
    var decodedJson = json.decode(utf8.decode(decodedPayload));
    if (decodedJson['type'] == type) {
      ScpResponseSetWifiConfig setWifiConfigResponse =
          ScpResponseSetWifiConfig(
        deviceId: decodedJson['deviceId'],
        result: decodedJson['result'],
      );
      return setWifiConfigResponse;
    }
  }
  return ScpResponseSetWifiConfig();
}