org.opensearch.common.blobstore.EncryptedBlobMetadata Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearch Show documentation
Show all versions of opensearch Show documentation
OpenSearch subproject :server
/*
* 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());
}
}