pymensago/auth.py
def add_device_session(db, address: WAddress, devid: UUID, devpair: EncryptionPair, 
	devname='') -> RetVal:
	'''Adds a device to a workspace'''

	if not address.is_valid():
		return RetVal(ErrBadValue, 'bad address')
	
	if not devid:
		return RetVal(ErrEmptyData)
	
	if devpair.enctype != 'CURVE25519':
		return RetVal(ErrUnsupportedAlgorithm, "enctype must be 'CURVE25519'")

	# address has to be valid and existing already
	cursor = db.cursor()
	cursor.execute("SELECT wid FROM workspaces WHERE wid=?",(address.id.as_string(),))
	results = cursor.fetchone()
	if not results or not results[0]:
		return RetVal(ErrNotFound)

	# Can't have a session on the server already
	cursor.execute("SELECT address FROM sessions WHERE address=?", (address.as_string(),))
	results = cursor.fetchone()
	if results:
		return RetVal(ErrExists)
	
	cursor = db.cursor()
	if not devname:
		devname = platform.node().casefold()
	
	osname = platform.system().casefold()

	# Use the name of the distro if running Linux
	if osname == 'linux' and distro.id():
		osname = distro.id().casefold()
		
	cursor.execute('''INSERT INTO sessions(
			address, devid, devname, public_key, private_key, os) 
			VALUES(?,?,?,?,?,?)''',
			(address.as_string(), devid.as_string(), devname, devpair.public.as_string(), 
			devpair.private.as_string(), osname))
	db.commit()
	return RetVal()
Adds a device to a workspace
Adds a device to a workspace
Adds a device to a workspace
def add_device_session(db, address: WAddress, devid: UUID, devpair: EncryptionPair, 
	devname='') -> RetVal:
	if not address.is_valid():
		return RetVal(ErrBadValue, 'bad address')
	if not devid:
		return RetVal(ErrEmptyData)
	if devpair.enctype != 'CURVE25519':
		return RetVal(ErrUnsupportedAlgorithm, "enctype must be 'CURVE25519'")
	cursor = db.cursor()
	cursor.execute("SELECT wid FROM workspaces WHERE wid=?",(address.id.as_string(),))
	results = cursor.fetchone()
	if not results or not results[0]:
		return RetVal(ErrNotFound)
	cursor.execute("SELECT address FROM sessions WHERE address=?", (address.as_string(),))
	results = cursor.fetchone()
	if results:
		return RetVal(ErrExists)
	cursor = db.cursor()
	if not devname:
		devname = platform.node().casefold()
	osname = platform.system().casefold()
	if osname == 'linux' and distro.id():
		osname = distro.id().casefold()
	cursor.execute('''INSERT INTO sessions(
			address, devid, devname, public_key, private_key, os) 
			VALUES(?,?,?,?,?,?)''',
			(address.as_string(), devid.as_string(), devname, devpair.public.as_string(), 
			devpair.private.as_string(), osname))
	db.commit()
	return RetVal()
def add_device_session ( db , address : WAddress , devid : UUID , devpair : EncryptionPair , devname = '' ) -> RetVal : if not address . is_valid ( ) : return RetVal ( ErrBadValue , 'bad address' ) if not devid : return RetVal ( ErrEmptyData ) if devpair . enctype != 'CURVE25519' : return RetVal ( ErrUnsupportedAlgorithm , "enctype must be 'CURVE25519'" ) cursor = db . cursor ( ) cursor . execute ( "SELECT wid FROM workspaces WHERE wid=?" , ( address . id . as_string ( ) , ) ) results = cursor . fetchone ( ) if not results or not results [ 0 ] : return RetVal ( ErrNotFound ) cursor . execute ( "SELECT address FROM sessions WHERE address=?" , ( address . as_string ( ) , ) ) results = cursor . fetchone ( ) if results : return RetVal ( ErrExists ) cursor = db . cursor ( ) if not devname : devname = platform . node ( ) . casefold ( ) osname = platform . system ( ) . casefold ( ) if osname == 'linux' and distro . id ( ) : osname = distro . id ( ) . casefold ( ) cursor . execute ( '''INSERT INTO sessions(
			address, devid, devname, public_key, private_key, os) 
			VALUES(?,?,?,?,?,?)''' , ( address . as_string ( ) , devid . as_string ( ) , devname , devpair . public . as_string ( ) , devpair . private . as_string ( ) , osname ) ) db . commit ( ) return RetVal ( )
Adds a device to a workspace
Adds a device to a workspace
'''Adds a device to a workspace''' # address has to be valid and existing already # Can't have a session on the server already # Use the name of the distro if running Linux
db
address
WAddress
devid
UUID
devpair
EncryptionPair
devname