All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opensearch.common.blobstore.EncryptedBlobMetadata Maven / Gradle / Ivy

There is a newer version: 2.18.0
Show newest version
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * The OpenSearch Contributors require contributions made to
 * this file be licensed under the Apache-2.0 license or a
 * compatible open source license.
 */

package org.opensearch.common.blobstore;

import org.opensearch.common.crypto.CryptoHandler;
import org.opensearch.common.crypto.EncryptedHeaderContentSupplier;

import java.io.IOException;

/**
 * Adjusts length of encrypted blob to raw length
 */
public class EncryptedBlobMetadata implements BlobMetadata {
    private final EncryptedHeaderContentSupplier encryptedHeaderContentSupplier;
    private final BlobMetadata delegate;
    private final CryptoHandler cryptoHandler;

    public EncryptedBlobMetadata(
        BlobMetadata delegate,
        CryptoHandler cryptoHandler,
        EncryptedHeaderContentSupplier encryptedHeaderContentSupplier
    ) {
        this.encryptedHeaderContentSupplier = encryptedHeaderContentSupplier;
        this.delegate = delegate;
        this.cryptoHandler = cryptoHandler;
    }

    @Override
    public String name() {
        return delegate.name();
    }

    @Override
    public long length() {
        U cryptoContext;
        try {
            cryptoContext = cryptoHandler.loadEncryptionMetadata(encryptedHeaderContentSupplier);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return cryptoHandler.estimateDecryptedLength(cryptoContext, delegate.length());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy