Skip to content

Commit f38f8e4

Browse files
committed
Updated EncryptOptions queryType to be a String
Allows for support for future new options and is inline with algorithm also not being an enum. JAVA-4643 JAVA-4644
1 parent c5f8ebc commit f38f8e4

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ext {
4848
nettyTcnativeBoringsslVersion = '2.0.48.Final'
4949
snappyVersion = '1.1.8.4'
5050
zstdVersion = '1.5.0-4'
51-
mongoCryptVersion = '1.5.0-rc1'
51+
mongoCryptVersion = '1.5.0-rc2'
5252
projectReactorVersion = 'Californium-SR23'
5353
junitBomVersion = '5.8.1'
5454
gitVersion = getGitVersion()

driver-core/src/main/com/mongodb/client/model/vault/EncryptOptions.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,7 @@ public class EncryptOptions {
3030
private String keyAltName;
3131
private final String algorithm;
3232
private Long contentionFactor;
33-
private QueryType queryType;
34-
35-
/**
36-
* The QueryType to use for "Indexed" queries
37-
*
38-
* @since 4.7
39-
*/
40-
@Beta(Beta.Reason.SERVER)
41-
public enum QueryType {
42-
/**
43-
* Equality query type
44-
*/
45-
EQUALITY
46-
}
33+
private String queryType;
4734

4835
/**
4936
* Construct an instance with the given algorithm.
@@ -153,28 +140,30 @@ public Long getContentionFactor() {
153140
/**
154141
* The QueryType.
155142
*
156-
* <p>It is an error to set queryType when algorithm is not "Indexed".</p>
143+
* <p>Currently, we support only "equality" queryType.</p>
144+
* <p>It is an error to set queryType when the algorithm is not "Indexed".</p>
157145
*
158146
* @param queryType the query type
159147
* @return this
160148
* @since 4.7
161149
*/
162150
@Beta(Beta.Reason.SERVER)
163-
public EncryptOptions queryType(@Nullable final QueryType queryType) {
151+
public EncryptOptions queryType(@Nullable final String queryType) {
164152
this.queryType = queryType;
165153
return this;
166154
}
167155

168156
/**
169157
* Gets the QueryType.
170158
*
171-
* @see #queryType(QueryType)
159+
* <p>Currently, we support only "equality" queryType.</p>
160+
* @see #queryType(String)
172161
* @return the queryType or null
173162
* @since 4.7
174163
*/
175164
@Nullable
176165
@Beta(Beta.Reason.SERVER)
177-
public QueryType getQueryType() {
166+
public String getQueryType() {
178167
return queryType;
179168
}
180169

driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/crypt/Crypt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public Mono<BsonBinary> encryptExplicitly(final BsonValue value, final EncryptOp
181181
}
182182

183183
if (options.getQueryType() != null) {
184-
encryptOptionsBuilder.queryType(MongoExplicitEncryptOptions.QueryType.valueOf(options.getQueryType().name()));
184+
encryptOptionsBuilder.queryType(options.getQueryType());
185185
}
186186

187187
return mongoCrypt.createExplicitEncryptionContext(new BsonDocument("v", value), encryptOptionsBuilder.build());

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ BsonBinary encryptExplicitly(final BsonValue value, final EncryptOptions options
197197
encryptOptionsBuilder.contentionFactor(options.getContentionFactor());
198198
}
199199

200-
EncryptOptions.QueryType queryType = options.getQueryType();
201-
if (queryType != null) {
202-
encryptOptionsBuilder.queryType(MongoExplicitEncryptOptions.QueryType.valueOf(queryType.name()));
200+
if (options.getQueryType() != null) {
201+
encryptOptionsBuilder.queryType(options.getQueryType());
203202
}
204203

205204
try (MongoCryptContext encryptionContext = mongoCrypt.createExplicitEncryptionContext(

driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideEncryptionExplicitEncryptionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void canInsertEncryptedIndexedAndFind() {
137137
.getCollection("explicit_encryption", BsonDocument.class);
138138
coll.insertOne(new BsonDocument("encryptedIndexed", insertPayload));
139139

140-
encryptOptions = new EncryptOptions("Indexed").keyId(key1Id).queryType(EncryptOptions.QueryType.EQUALITY);
140+
encryptOptions = new EncryptOptions("Indexed").keyId(key1Id).queryType("equality");
141141
BsonBinary findPayload = clientEncryption.encrypt(ENCRYPTED_INDEXED_VALUE, encryptOptions);
142142

143143
BsonDocument actual = coll.find(new BsonDocument("encryptedIndexed", findPayload)).first();
@@ -156,7 +156,7 @@ public void canInsertEncryptedIndexedAndFindWithNonZeroContention() {
156156
coll.insertOne(new BsonDocument("encryptedIndexed", insertPayload));
157157
}
158158

159-
encryptOptions = new EncryptOptions("Indexed").keyId(key1Id).queryType(EncryptOptions.QueryType.EQUALITY);
159+
encryptOptions = new EncryptOptions("Indexed").keyId(key1Id).queryType("equality");
160160
BsonBinary findPayload = clientEncryption.encrypt(ENCRYPTED_INDEXED_VALUE, encryptOptions);
161161

162162
List<BsonDocument> values = coll.find(new BsonDocument("encryptedIndexed", findPayload)).into(new ArrayList<>());
@@ -165,7 +165,7 @@ public void canInsertEncryptedIndexedAndFindWithNonZeroContention() {
165165
assertEquals(ENCRYPTED_INDEXED_VALUE, v.get("encryptedIndexed"))
166166
);
167167

168-
encryptOptions = new EncryptOptions("Indexed").keyId(key1Id).contentionFactor(10L).queryType(EncryptOptions.QueryType.EQUALITY);
168+
encryptOptions = new EncryptOptions("Indexed").keyId(key1Id).contentionFactor(10L).queryType("equality");
169169
BsonBinary findPayload2 = clientEncryption.encrypt(ENCRYPTED_INDEXED_VALUE, encryptOptions);
170170

171171
values = coll.find(new BsonDocument("encryptedIndexed", findPayload2)).into(new ArrayList<>());

0 commit comments

Comments
 (0)