Skip to content

Commit 3cb1fe7

Browse files
committed
Crypt.java added assertNotNull for required values
1 parent 7f5e85c commit 3cb1fe7

File tree

1 file changed

+6
-8
lines changed
  • driver-sync/src/main/com/mongodb/client/internal

1 file changed

+6
-8
lines changed

driver-sync/src/main/com/mongodb/client/internal/Crypt.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.mongodb.MongoClientException;
2020
import com.mongodb.MongoException;
2121
import com.mongodb.MongoInternalException;
22+
import com.mongodb.assertions.Assertions;
2223
import com.mongodb.client.MongoClient;
2324
import com.mongodb.client.model.vault.DataKeyOptions;
2425
import com.mongodb.client.model.vault.EncryptOptions;
@@ -42,6 +43,7 @@
4243
import java.util.Map;
4344
import java.util.function.Supplier;
4445

46+
import static com.mongodb.assertions.Assertions.assertNotNull;
4547
import static com.mongodb.assertions.Assertions.notNull;
4648
import static com.mongodb.crypt.capi.MongoCryptContext.State;
4749

@@ -220,7 +222,7 @@ BsonValue decryptExplicitly(final BsonBinary value) {
220222
notNull("value", value);
221223

222224
try (MongoCryptContext decryptionContext = mongoCrypt.createExplicitDecryptionContext(new BsonDocument("v", value))) {
223-
return executeStateMachine(decryptionContext, null).get("v");
225+
return assertNotNull(executeStateMachine(decryptionContext, null).get("v"));
224226
} catch (MongoCryptException e) {
225227
throw wrapInClientException(e);
226228
}
@@ -238,10 +240,6 @@ public void close() {
238240
}
239241
}
240242

241-
public String getCryptSharedLibVersionString() {
242-
return mongoCrypt.getCryptSharedLibVersionString();
243-
}
244-
245243
private RawBsonDocument executeStateMachine(final MongoCryptContext cryptContext, @Nullable final String databaseName) {
246244
while (true) {
247245
State state = cryptContext.getState();
@@ -275,7 +273,7 @@ private void fetchCredentials(final MongoCryptContext cryptContext) {
275273

276274
private void collInfo(final MongoCryptContext cryptContext, final String databaseName) {
277275
try {
278-
BsonDocument collectionInfo = collectionInfoRetriever.filter(databaseName, cryptContext.getMongoOperation());
276+
BsonDocument collectionInfo = assertNotNull(collectionInfoRetriever).filter(databaseName, cryptContext.getMongoOperation());
279277
if (collectionInfo != null) {
280278
cryptContext.addMongoOperationResult(collectionInfo);
281279
}
@@ -287,7 +285,7 @@ private void collInfo(final MongoCryptContext cryptContext, final String databas
287285

288286
private void mark(final MongoCryptContext cryptContext, final String databaseName) {
289287
try {
290-
RawBsonDocument markedCommand = commandMarker.mark(databaseName, cryptContext.getMongoOperation());
288+
RawBsonDocument markedCommand = assertNotNull(commandMarker).mark(databaseName, cryptContext.getMongoOperation());
291289
cryptContext.addMongoOperationResult(markedCommand);
292290
cryptContext.completeMongoOperation();
293291
} catch (Throwable t) {
@@ -319,7 +317,7 @@ private void decryptKeys(final MongoCryptContext cryptContext) {
319317
}
320318
}
321319

322-
private void decryptKey(final MongoKeyDecryptor keyDecryptor) throws IOException {
320+
private void decryptKey(final MongoKeyDecryptor keyDecryptor) {
323321
try (InputStream inputStream = keyManagementService.stream(keyDecryptor.getKmsProvider(), keyDecryptor.getHostName(),
324322
keyDecryptor.getMessage())) {
325323
int bytesNeeded = keyDecryptor.bytesNeeded();

0 commit comments

Comments
 (0)