Search in sources :

Example 1 with ByteBufferBackedDataInputImpl

use of org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferBackedDataInputImpl in project ignite by apache.

the class RecordDataV1Serializer method readEncryptedData.

/**
 * Reads and decrypt data from {@code in} stream.
 *
 * @param in Input stream.
 * @param readType If {@code true} plain record type will be read from {@code in}.
 * @param readKeyId If {@code true} encryption key identifier will be read from {@code in}.
 * @return Plain data stream, group id, plain record type,
 * @throws IOException If failed.
 * @throws IgniteCheckedException If failed.
 */
private T3<ByteBufferBackedDataInput, Integer, RecordType> readEncryptedData(ByteBufferBackedDataInput in, boolean readType, boolean readKeyId) throws IOException, IgniteCheckedException {
    int grpId = in.readInt();
    int encRecSz = in.readInt();
    RecordType plainRecType = null;
    if (readType)
        plainRecType = RecordV1Serializer.readRecordType(in);
    int keyId = readKeyId ? in.readUnsignedByte() : GridEncryptionManager.INITIAL_KEY_ID;
    byte[] encData = new byte[encRecSz];
    in.readFully(encData);
    GroupKey grpKey = encMgr.groupKey(grpId, keyId);
    if (grpKey == null)
        return new T3<>(null, grpId, plainRecType);
    byte[] clData = encSpi.decrypt(encData, grpKey.key());
    return new T3<>(new ByteBufferBackedDataInputImpl().buffer(ByteBuffer.wrap(clData)), grpId, plainRecType);
}
Also used : RecordV1Serializer.putRecordType(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.putRecordType) RecordType(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType) GroupKey(org.apache.ignite.internal.managers.encryption.GroupKey) ByteBufferBackedDataInputImpl(org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferBackedDataInputImpl) T3(org.apache.ignite.internal.util.typedef.T3)

Example 2 with ByteBufferBackedDataInputImpl

use of org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferBackedDataInputImpl in project gridgain by gridgain.

the class RecordDataV1Serializer method readEncryptedData.

/**
 * Reads and decrypt data from {@code in} stream.
 *
 * @param in Input stream.
 * @param readType If {@code true} plain record type will be read from {@code in}.
 * @param readKeyId If {@code true} encryption key identifier will be read from {@code in}.
 * @return Plain data stream, group id, plain record type,
 * @throws IOException If failed.
 * @throws IgniteCheckedException If failed.
 */
private T3<ByteBufferBackedDataInput, Integer, RecordType> readEncryptedData(ByteBufferBackedDataInput in, boolean readType, boolean readKeyId) throws IOException, IgniteCheckedException {
    int grpId = in.readInt();
    int encRecSz = in.readInt();
    RecordType plainRecType = null;
    if (readType)
        plainRecType = RecordV1Serializer.readRecordType(in);
    int keyId = readKeyId ? in.readUnsignedByte() : GridEncryptionManager.INITIAL_KEY_ID;
    byte[] encData = new byte[encRecSz];
    in.readFully(encData);
    GroupKey grpKey = encMgr.groupKey(grpId, keyId);
    if (grpKey == null)
        return new T3<>(null, grpId, plainRecType);
    byte[] clData = encSpi.decrypt(encData, grpKey.key());
    return new T3<>(new ByteBufferBackedDataInputImpl().buffer(ByteBuffer.wrap(clData)), grpId, plainRecType);
}
Also used : RecordV1Serializer.putRecordType(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.putRecordType) RecordType(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType) GroupKey(org.apache.ignite.internal.managers.encryption.GroupKey) ByteBufferBackedDataInputImpl(org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferBackedDataInputImpl) T3(org.apache.ignite.internal.util.typedef.T3)

Aggregations

GroupKey (org.apache.ignite.internal.managers.encryption.GroupKey)2 RecordType (org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType)2 ByteBufferBackedDataInputImpl (org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferBackedDataInputImpl)2 RecordV1Serializer.putRecordType (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.putRecordType)2 T3 (org.apache.ignite.internal.util.typedef.T3)2