Search in sources :

Example 1 with StreamCipherProvider

use of jetbrains.exodus.crypto.StreamCipherProvider in project xodus by JetBrains.

the class LogRecoveryTest method cutAndCheckLastLoggableIncomplete.

private void cutAndCheckLastLoggableIncomplete(int cutSize, int max) {
    openStoreAutoCommit("new_store", StoreConfig.WITHOUT_DUPLICATES);
    /*final Iterator<Loggable> itr = getLog().getLoggablesIterator(0);
        while (itr.hasNext()) {
            final Loggable next = itr.next();
            System.out.println(next.getType() + " @ " + next.getAddress());
        }*/
    assertLoggableTypes(getLog(), 0, seq);
    env.close();
    final StreamCipherProvider cipherProvider = env.getCipherProvider();
    final byte[] cipherKey = env.getCipherKey();
    final long cipherBasicIV = env.getCipherBasicIV();
    env = null;
    final long size = reader.getBlock(0).length();
    writer.openOrCreateBlock(0, size - cutSize);
    writer.close();
    // only 'max' first loggables should remain
    final LogConfig config = LogConfig.create(reader, writer).setCipherProvider(cipherProvider).setCipherKey(cipherKey).setCipherBasicIV(cipherBasicIV);
    final Log newLog = Environments.newLogInstance(config);
    newLog.setHighAddress(newLog.getTip(), newLog.getTip().approvedHighAddress);
    assertLoggableTypes(max, newLog.getLoggableIterator(0), seq);
}
Also used : Log(jetbrains.exodus.log.Log) StreamCipherProvider(jetbrains.exodus.crypto.StreamCipherProvider) LogConfig(jetbrains.exodus.log.LogConfig)

Example 2 with StreamCipherProvider

use of jetbrains.exodus.crypto.StreamCipherProvider in project xodus by JetBrains.

the class Log method readBytes.

@SuppressWarnings("ConstantConditions")
int readBytes(final byte[] output, final long address) {
    final long fileAddress = getFileAddress(address);
    final LogTip logTip = getTip();
    final LongIterator files = logTip.logFileSet.getFilesFrom(fileAddress);
    if (files.hasNext()) {
        final long leftBound = files.nextLong();
        final long fileSize = getFileSize(leftBound, logTip);
        if (leftBound == fileAddress && fileAddress + fileSize > address) {
            final Block block = reader.getBlock(fileAddress);
            final int readBytes = block.read(output, address - fileAddress, output.length);
            final StreamCipherProvider cipherProvider = config.getCipherProvider();
            if (cipherProvider != null) {
                EnvKryptKt.cryptBlocksMutable(cipherProvider, config.getCipherKey(), config.getCipherBasicIV(), address, output, 0, readBytes, LogUtil.LOG_BLOCK_ALIGNMENT);
            }
            notifyReadBytes(output, readBytes);
            return readBytes;
        }
        if (fileAddress < logTip.logFileSet.getMinimum()) {
            BlockNotFoundException.raise("Address is out of log space, underflow", this, address);
        }
        if (fileAddress >= logTip.logFileSet.getMaximum()) {
            BlockNotFoundException.raise("Address is out of log space, overflow", this, address);
        }
    }
    BlockNotFoundException.raise(this, address);
    return 0;
}
Also used : Block(jetbrains.exodus.io.Block) StreamCipherProvider(jetbrains.exodus.crypto.StreamCipherProvider) LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator)

Aggregations

StreamCipherProvider (jetbrains.exodus.crypto.StreamCipherProvider)2 LongIterator (jetbrains.exodus.core.dataStructures.hash.LongIterator)1 Block (jetbrains.exodus.io.Block)1 Log (jetbrains.exodus.log.Log)1 LogConfig (jetbrains.exodus.log.LogConfig)1