def compute_storage_size(cls, block_size, block_count, bucket_capacity=4, heap_base=2, ignore_header=False, **kwds): assert (block_size > 0) and (block_size == int(block_size)) assert (block_count > 0) and (block_count == int(block_count)) assert bucket_capacity >= 1 assert heap_base >= 2 assert 'heap_height' not in kwds heap_height = calculate_necessary_heap_height(heap_base, block_count) block_size += TreeORAMStorageManagerExplicitAddressing.\ block_info_storage_size if ignore_header: return EncryptedHeapStorage.compute_storage_size( block_size, heap_height, blocks_per_bucket=bucket_capacity, heap_base=heap_base, ignore_header=True, **kwds) else: return cls._header_offset + \ EncryptedHeapStorage.compute_storage_size( block_size, heap_height, blocks_per_bucket=bucket_capacity, heap_base=heap_base, ignore_header=False, **kwds)
def compute_storage_size(cls, block_size, block_count, bucket_capacity=4, heap_base=2, ignore_header=False, **kwds): assert (block_size > 0) and (block_size == int(block_size)) assert (block_count > 0) and (block_count == int(block_count)) assert bucket_capacity >= 1 assert heap_base >= 2 assert 'heap_height' not in kwds heap_height = calculate_necessary_heap_height(heap_base, block_count) block_size += TreeORAMStorageManagerExplicitAddressing.\ block_info_storage_size if ignore_header: return EncryptedHeapStorage.compute_storage_size( block_size, heap_height, blocks_per_bucket=bucket_capacity, heap_base=heap_base, ignore_header=True, **kwds) else: return cls._header_offset + \ EncryptedHeapStorage.compute_storage_size( block_size, heap_height, blocks_per_bucket=bucket_capacity, heap_base=heap_base, ignore_header=False, **kwds)
def test_setup_withdata(self): fname = ".".join(self.id().split(".")[1:]) fname += ".bin" fname = os.path.join(thisdir, fname) if os.path.exists(fname): os.remove(fname) # pragma: no cover bsize = 10 heap_height = 2 blocks_per_bucket = 1 header_data = bytes(bytearray([0, 1, 2])) fsetup = EncryptedHeapStorage.setup( fname, bsize, heap_height, key_size=AES.key_sizes[0], blocks_per_bucket=blocks_per_bucket, header_data=header_data) fsetup.close() self.assertEqual(type(fsetup.raw_storage), BlockStorageTypeFactory(self._type_name)) with open(fname, 'rb') as f: flen = len(f.read()) self.assertEqual( flen, EncryptedHeapStorage.compute_storage_size( bsize, heap_height, header_data=header_data)) self.assertTrue(len(header_data) > 0) self.assertEqual( EncryptedHeapStorage.compute_storage_size( bsize, heap_height, storage_type=self._type_name) < EncryptedHeapStorage.compute_storage_size( bsize, heap_height, storage_type=self._type_name, header_data=header_data), True) self.assertEqual( flen > EncryptedHeapStorage.compute_storage_size( bsize, heap_height, storage_type=self._type_name, header_data=header_data, ignore_header=True), True) with EncryptedHeapStorage(fname, key=fsetup.key, storage_type=self._type_name) as f: self.assertEqual(f.header_data, header_data) self.assertEqual(fsetup.header_data, header_data) self.assertEqual(f.key, fsetup.key) self.assertEqual(f.blocks_per_bucket, blocks_per_bucket) self.assertEqual(fsetup.blocks_per_bucket, blocks_per_bucket) self.assertEqual(f.bucket_count, 2**(heap_height + 1) - 1) self.assertEqual(fsetup.bucket_count, 2**(heap_height + 1) - 1) self.assertEqual(f.bucket_size, bsize * blocks_per_bucket) self.assertEqual(fsetup.bucket_size, bsize * blocks_per_bucket) self.assertEqual(f.storage_name, fname) self.assertEqual(fsetup.storage_name, fname) os.remove(fname)
def test_setup(self): fname = ".".join(self.id().split(".")[1:]) fname += ".bin" fname = os.path.join(thisdir, fname) if os.path.exists(fname): os.remove(fname) # pragma: no cover bsize = 10 heap_height = 2 blocks_per_bucket = 3 fsetup = EncryptedHeapStorage.setup( fname, bsize, heap_height, key_size=AES.key_sizes[0], blocks_per_bucket=blocks_per_bucket) fsetup.close() self.assertEqual(type(fsetup.raw_storage), BlockStorageTypeFactory(self._type_name)) with open(fname, 'rb') as f: flen = len(f.read()) self.assertEqual( flen, EncryptedHeapStorage.compute_storage_size( bsize, heap_height, blocks_per_bucket=blocks_per_bucket)) self.assertEqual( flen > EncryptedHeapStorage.compute_storage_size( bsize, heap_height, blocks_per_bucket=blocks_per_bucket, ignore_header=True), True) with EncryptedHeapStorage( fname, key=fsetup.key, storage_type=self._type_name) as f: self.assertEqual(f.header_data, bytes()) self.assertEqual(fsetup.header_data, bytes()) self.assertEqual(f.key, fsetup.key) self.assertEqual(f.blocks_per_bucket, blocks_per_bucket) self.assertEqual(fsetup.blocks_per_bucket, blocks_per_bucket) self.assertEqual(f.bucket_count, 2**(heap_height+1) - 1) self.assertEqual(fsetup.bucket_count, 2**(heap_height+1) - 1) self.assertEqual(f.bucket_size, bsize * blocks_per_bucket) self.assertEqual(fsetup.bucket_size, bsize * blocks_per_bucket) self.assertEqual(f.storage_name, fname) self.assertEqual(fsetup.storage_name, fname) os.remove(fname)
def compute_storage_size(cls, *args, **kwds): return EncryptedHeapStorage.compute_storage_size(*args, **kwds)
def compute_storage_size(cls, *args, **kwds): return EncryptedHeapStorage.compute_storage_size(*args, **kwds)