diff --git a/driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java b/driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java index 52f351b20b6..27da74047a0 100644 --- a/driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java +++ b/driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java @@ -134,6 +134,13 @@ private static BsonDocument toBsonDocument(final Map optionsMap) return new BsonDocumentWrapper<>(new Document(optionsMap), new DocumentCodec()); } + public static boolean isMongocryptdSpawningDisabled(@Nullable final String cryptSharedLibVersion, + final AutoEncryptionSettings settings) { + boolean cryptSharedLibIsAvailable = cryptSharedLibVersion != null && cryptSharedLibVersion.isEmpty(); + boolean cryptSharedLibRequired = (boolean) settings.getExtraOptions().getOrDefault("cryptSharedLibRequired", false); + return settings.isBypassAutoEncryption() || settings.isBypassQueryAnalysis() || cryptSharedLibRequired || cryptSharedLibIsAvailable; + } + @SuppressWarnings("unchecked") public static List createMongocryptdSpawnArgs(final Map options) { List spawnArgs = new ArrayList<>(); diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/CommandMarker.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/CommandMarker.java index e5b97c58dc8..69524dfa772 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/CommandMarker.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/CommandMarker.java @@ -34,6 +34,7 @@ import static com.mongodb.assertions.Assertions.assertNotNull; import static com.mongodb.internal.capi.MongoCryptHelper.createMongocryptdClientSettings; import static com.mongodb.internal.capi.MongoCryptHelper.createProcessBuilder; +import static com.mongodb.internal.capi.MongoCryptHelper.isMongocryptdSpawningDisabled; import static com.mongodb.internal.capi.MongoCryptHelper.startProcess; @SuppressWarnings("UseOfProcessBuilder") @@ -62,18 +63,12 @@ class CommandMarker implements Closeable { CommandMarker( final MongoCrypt mongoCrypt, final AutoEncryptionSettings settings) { - Map extraOptions = settings.getExtraOptions(); - String cryptSharedLibVersionString = mongoCrypt.getCryptSharedLibVersionString(); - boolean bypassAutoEncryption = settings.isBypassAutoEncryption(); - boolean isBypassQueryAnalysis = settings.isBypassQueryAnalysis(); - boolean cryptSharedIsAvailable = cryptSharedLibVersionString != null && cryptSharedLibVersionString.isEmpty(); - boolean cryptSharedLibRequired = (boolean) extraOptions.getOrDefault("cryptSharedLibRequired", false); - - if (bypassAutoEncryption || isBypassQueryAnalysis || cryptSharedLibRequired || cryptSharedIsAvailable) { + if (isMongocryptdSpawningDisabled(mongoCrypt.getCryptSharedLibVersionString(), settings)) { processBuilder = null; client = null; } else { + Map extraOptions = settings.getExtraOptions(); boolean mongocryptdBypassSpawn = (boolean) extraOptions.getOrDefault("mongocryptdBypassSpawn", false); if (!mongocryptdBypassSpawn) { processBuilder = createProcessBuilder(extraOptions); diff --git a/driver-sync/src/main/com/mongodb/client/internal/CommandMarker.java b/driver-sync/src/main/com/mongodb/client/internal/CommandMarker.java index 6afcfb5864a..e85bc44eb8f 100644 --- a/driver-sync/src/main/com/mongodb/client/internal/CommandMarker.java +++ b/driver-sync/src/main/com/mongodb/client/internal/CommandMarker.java @@ -34,6 +34,7 @@ import static com.mongodb.assertions.Assertions.assertNotNull; import static com.mongodb.internal.capi.MongoCryptHelper.createMongocryptdClientSettings; import static com.mongodb.internal.capi.MongoCryptHelper.createProcessBuilder; +import static com.mongodb.internal.capi.MongoCryptHelper.isMongocryptdSpawningDisabled; import static com.mongodb.internal.capi.MongoCryptHelper.startProcess; @SuppressWarnings("UseOfProcessBuilder") @@ -62,18 +63,12 @@ class CommandMarker implements Closeable { CommandMarker( final MongoCrypt mongoCrypt, final AutoEncryptionSettings settings) { - Map extraOptions = settings.getExtraOptions(); - String cryptSharedLibVersionString = mongoCrypt.getCryptSharedLibVersionString(); - boolean bypassAutoEncryption = settings.isBypassAutoEncryption(); - boolean isBypassQueryAnalysis = settings.isBypassQueryAnalysis(); - boolean cryptSharedIsAvailable = cryptSharedLibVersionString != null && cryptSharedLibVersionString.isEmpty(); - boolean cryptSharedLibRequired = (boolean) extraOptions.getOrDefault("cryptSharedLibRequired", false); - - if (bypassAutoEncryption || isBypassQueryAnalysis || cryptSharedLibRequired || cryptSharedIsAvailable) { + if (isMongocryptdSpawningDisabled(mongoCrypt.getCryptSharedLibVersionString(), settings)) { processBuilder = null; client = null; } else { + Map extraOptions = settings.getExtraOptions(); boolean mongocryptdBypassSpawn = (boolean) extraOptions.getOrDefault("mongocryptdBypassSpawn", false); if (!mongocryptdBypassSpawn) { processBuilder = createProcessBuilder(extraOptions);