def enc_file_generator(self, user, decrypter, dFile, fileId=None, publicShareId=None): endOfFile = False readData = dFile.read(1024*8) data = decrypter.decrypt(readData) #If the data is less than one block long, just process it and send it out #try: if len(data) < (1024*8): padding = int(str(data[-1:]),16) #A 0 represents that the file had a multiple of 16 bytes, and 16 bytes of padding were added if padding==0: padding=16 endOfFile = True FileService.file_download_complete(user, fileId, publicShareId) yield data[:len(data)-padding] else: #For multiblock files while True: if endOfFile: FileService.file_download_complete(user, fileId, publicShareId) break next_data = decrypter.decrypt(dFile.read(1024*8)) if (next_data is not None and next_data != "") and not len(next_data)<(1024*8): yData = data data = next_data yield yData #This prevents padding going across block boundaries by aggregating the last two blocks and processing #as a whole if the next block is less than a full block (signifying end of file) else: data = data + next_data padding = int(str(data[-1:]),16) #A 0 represents that the file had a multiple of 16 bytes, and 16 bytes of padding were added if padding==0: padding=16 endOfFile = True yield data[:len(data)-padding]
def enc_file_generator(self, user, decrypter, dFile, fileId=None, publicShareId=None): endOfFile = False readData = dFile.read(1024 * 8) data = decrypter.decrypt(readData) #If the data is less than one block long, just process it and send it out #try: if len(data) < (1024 * 8): padding = int(str(data[-1:]), 16) #A 0 represents that the file had a multiple of 16 bytes, and 16 bytes of padding were added if padding == 0: padding = 16 endOfFile = True FileService.file_download_complete(user, fileId, publicShareId) yield data[:len(data) - padding] else: #For multiblock files while True: if endOfFile: FileService.file_download_complete(user, fileId, publicShareId) break next_data = decrypter.decrypt(dFile.read(1024 * 8)) if (next_data is not None and next_data != "") and not len(next_data) < (1024 * 8): yData = data data = next_data yield yData #This prevents padding going across block boundaries by aggregating the last two blocks and processing #as a whole if the next block is less than a full block (signifying end of file) else: data = data + next_data padding = int(str(data[-1:]), 16) #A 0 represents that the file had a multiple of 16 bytes, and 16 bytes of padding were added if padding == 0: padding = 16 endOfFile = True yield data[:len(data) - padding]