fromJson static method
Implementation
static Future<ScpResponseMeasure> fromJson(var inputJson, String password)async {
if (!InputValidation.validateJsonResponse(inputJson)) {
return ScpResponseMeasure();
}
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) {
ScpResponseMeasure measureResponse = ScpResponseMeasure(
action: decodedJson['action'],
deviceId: decodedJson['deviceId'],
value: decodedJson['value'],
result: decodedJson['result'],
);
return measureResponse;
}
}
return ScpResponseMeasure();
}