pymensago/iscmds.py
def device(conn: ServerConnection, devid: utils.UUID, devpair: EncryptionPair) -> RetVal:
	'''Completes the login process by submitting device ID and its session string.'''
	if not devid.is_valid():
		return RetVal(MsgBadRequest, 'Invalid device ID').set_value('status', 400)

	status = conn.send_message({
		'Action' : "DEVICE",
		'Data' : { 
			'Device-ID' : devid.as_string(),
			'Device-Key' : devpair.public.as_string()
		}
	})
	if status.error():
		return status

	# Receive, decrypt, and return the server challenge
	response = conn.read_response(server_response)
	if response.error():
		return response
	
	if response['Code'] != 100:
		return wrap_server_error(response)

	if 'Challenge' not in response['Data']:
		return RetVal(ErrServerError, 'server did not return a device challenge')
	
	status = devpair.decrypt(response['Data']['Challenge'])
	if status.error():
		cancel(conn)
		return RetVal(DecryptionFailure, 'failed to decrypt device challenge')

	status = conn.send_message({
		'Action' : "DEVICE",
		'Data' : { 
			'Device-ID' : devid.as_string(),
			'Device-Key' : devpair.public.as_string(),
			'Response' : status['data']
		}
	})
	if status.error():
		return status

	response = conn.read_response(None)
	if response.error():
		return response
	
	if response['Code'] != 200:
		return wrap_server_error(response)
	
	return RetVal().set_value('isadmin', response['Data']['Is-Admin'] == "True")
Completes the login process by submitting device ID and its session string.
Completes the login process by submitting device ID and its session string.
Completes the login process by submitting device ID and its session string .
def device(conn: ServerConnection, devid: utils.UUID, devpair: EncryptionPair) -> RetVal:
	if not devid.is_valid():
		return RetVal(MsgBadRequest, 'Invalid device ID').set_value('status', 400)
	status = conn.send_message({
		'Action' : "DEVICE",
		'Data' : { 
			'Device-ID' : devid.as_string(),
			'Device-Key' : devpair.public.as_string()
		}
	})
	if status.error():
		return status
	response = conn.read_response(server_response)
	if response.error():
		return response
	if response['Code'] != 100:
		return wrap_server_error(response)
	if 'Challenge' not in response['Data']:
		return RetVal(ErrServerError, 'server did not return a device challenge')
	status = devpair.decrypt(response['Data']['Challenge'])
	if status.error():
		cancel(conn)
		return RetVal(DecryptionFailure, 'failed to decrypt device challenge')
	status = conn.send_message({
		'Action' : "DEVICE",
		'Data' : { 
			'Device-ID' : devid.as_string(),
			'Device-Key' : devpair.public.as_string(),
			'Response' : status['data']
		}
	})
	if status.error():
		return status
	response = conn.read_response(None)
	if response.error():
		return response
	if response['Code'] != 200:
		return wrap_server_error(response)
	return RetVal().set_value('isadmin', response['Data']['Is-Admin'] == "True")
def device ( conn : ServerConnection , devid : utils . UUID , devpair : EncryptionPair ) -> RetVal : if not devid . is_valid ( ) : return RetVal ( MsgBadRequest , 'Invalid device ID' ) . set_value ( 'status' , 400 ) status = conn . send_message ( { 'Action' : "DEVICE" , 'Data' : { 'Device-ID' : devid . as_string ( ) , 'Device-Key' : devpair . public . as_string ( ) } } ) if status . error ( ) : return status response = conn . read_response ( server_response ) if response . error ( ) : return response if response [ 'Code' ] != 100 : return wrap_server_error ( response ) if 'Challenge' not in response [ 'Data' ] : return RetVal ( ErrServerError , 'server did not return a device challenge' ) status = devpair . decrypt ( response [ 'Data' ] [ 'Challenge' ] ) if status . error ( ) : cancel ( conn ) return RetVal ( DecryptionFailure , 'failed to decrypt device challenge' ) status = conn . send_message ( { 'Action' : "DEVICE" , 'Data' : { 'Device-ID' : devid . as_string ( ) , 'Device-Key' : devpair . public . as_string ( ) , 'Response' : status [ 'data' ] } } ) if status . error ( ) : return status response = conn . read_response ( None ) if response . error ( ) : return response if response [ 'Code' ] != 200 : return wrap_server_error ( response ) return RetVal ( ) . set_value ( 'isadmin' , response [ 'Data' ] [ 'Is-Admin' ] == "True" )
Completes the login process by submitting device ID and its session string.
Completes the login process by submitting device ID and its session string .
'''Completes the login process by submitting device ID and its session string.''' # Receive, decrypt, and return the server challenge
conn
ServerConnection
devid
utils.UUID
devpair
EncryptionPair