def verify_signed_data(token, data):
 if data.startswith(MAC_MARKER):
  try:
   data = data[len(MAC_MARKER):]
   mac_data = json.loads(base64.b64decode(data))
   mac = compute_mac(token, mac_data['serialized_data'])
   if (mac != mac_data['mac']):
    raise InvalidMacError(('invalid MAC; expect=%s, actual=%s' % (mac_data['mac'], mac)))
   return json.loads(mac_data['serialized_data'])
  except:
   raise InvalidMacError('invalid MAC; data appeared to be corrupted')
 else:
  return data

def verify_signed_data ( token , data ) : if data . startswith ( MAC_MARKER ) : try : data = data [ len ( MAC_MARKER ) : ] mac_data = json . loads ( base64 . b64decode ( data ) ) mac = compute_mac ( token , mac_data [ 'serialized_data' ] ) if ( mac != mac_data [ 'mac' ] ) : raise InvalidMacError ( ( 'invalid MAC; expect=%s, actual=%s' % ( mac_data [ 'mac' ] , mac ) ) ) return json . loads ( mac_data [ 'serialized_data' ] ) except : raise InvalidMacError ( 'invalid MAC; data appeared to be corrupted' ) else : return data
verify data integrity by ensuring mac is valid .