pymensago/envelope.py
def marshall(self) -> RetVal:
		'''Converts the object to the task-specific text format for Mensago data files'''
		
		# We have a lot of validation to do before we can actually generate the string
		if not self.msgkey.is_valid():
			return RetVal(RequiredDataMissing, 'message key missing')
		
		if not cs.CryptoString(self.fields['KeyHash']).is_valid():
			return RetVal(ErrInternalError, 'BUG: bad msg key hash')
		
		if cs.CryptoString(self.fields['PayloadKey']).is_valid():
			return RetVal(ErrInternalError, 'BUG: bad payload key')
		
		if self.fields['Version'] != '1.0':
			return RetVal(ErrBadData, 'bad version value')
		
		# Marshall and encrypt the payload. Because the internal structure of the payload varies,
		# we have to assume that the payload is valid. Minimal validation is possible, but largely
		# pointless
		try:
			envstr = json.dumps(self.fields)
		except Exception as e:
			return RetVal.wrap_exception(e)
		
		status = self.msgkey.encrypt(json.dumps(self.fields).encode())
		if status.error():
			return status

		return RetVal().set_value('envelope',
					'\n'.join(['MENSAGO', envstr, '----------', self.msgkey.key.prefix,
					status['data']]))
Converts the object to the task-specific text format for Mensago data files
Converts the object to the task-specific text format for Mensago data files
Converts the object to the task - specific text format for Mensago data files
def marshall(self) -> RetVal:
		if not self.msgkey.is_valid():
			return RetVal(RequiredDataMissing, 'message key missing')
		if not cs.CryptoString(self.fields['KeyHash']).is_valid():
			return RetVal(ErrInternalError, 'BUG: bad msg key hash')
		if cs.CryptoString(self.fields['PayloadKey']).is_valid():
			return RetVal(ErrInternalError, 'BUG: bad payload key')
		if self.fields['Version'] != '1.0':
			return RetVal(ErrBadData, 'bad version value')
		try:
			envstr = json.dumps(self.fields)
		except Exception as e:
			return RetVal.wrap_exception(e)
		status = self.msgkey.encrypt(json.dumps(self.fields).encode())
		if status.error():
			return status
		return RetVal().set_value('envelope',
					'\n'.join(['MENSAGO', envstr, '----------', self.msgkey.key.prefix,
					status['data']]))
def marshall ( self ) -> RetVal : if not self . msgkey . is_valid ( ) : return RetVal ( RequiredDataMissing , 'message key missing' ) if not cs . CryptoString ( self . fields [ 'KeyHash' ] ) . is_valid ( ) : return RetVal ( ErrInternalError , 'BUG: bad msg key hash' ) if cs . CryptoString ( self . fields [ 'PayloadKey' ] ) . is_valid ( ) : return RetVal ( ErrInternalError , 'BUG: bad payload key' ) if self . fields [ 'Version' ] != '1.0' : return RetVal ( ErrBadData , 'bad version value' ) try : envstr = json . dumps ( self . fields ) except Exception as e : return RetVal . wrap_exception ( e ) status = self . msgkey . encrypt ( json . dumps ( self . fields ) . encode ( ) ) if status . error ( ) : return status return RetVal ( ) . set_value ( 'envelope' , '\n' . join ( [ 'MENSAGO' , envstr , '----------' , self . msgkey . key . prefix , status [ 'data' ] ] ) )
Converts the object to the task-specific text format for Mensago data files
Converts the object to the task - specific text format for Mensago data files
'''Converts the object to the task-specific text format for Mensago data files''' # We have a lot of validation to do before we can actually generate the string # Marshall and encrypt the payload. Because the internal structure of the payload varies, # we have to assume that the payload is valid. Minimal validation is possible, but largely # pointless
self