Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA-5584: Move mongodb-crypt classes to internal package #1500

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@

<!-- mongocrypt -->
<Match>
<Class name="com.mongodb.crypt.capi.CAPI$cstring"/>
<Class name="com.mongodb.internal.crypt.capi.CAPI$cstring"/>
<Bug pattern="NM_CLASS_NAMING_CONVENTION"/>
</Match>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*
*/

import com.mongodb.crypt.capi.CAPI;
import com.mongodb.crypt.capi.MongoCrypt;
import com.mongodb.crypt.capi.MongoCryptContext;
import com.mongodb.crypt.capi.MongoCryptOptions;
import com.mongodb.crypt.capi.MongoCrypts;
import com.mongodb.crypt.capi.MongoExplicitEncryptOptions;
import com.mongodb.crypt.capi.MongoLocalKmsProviderOptions;
import com.mongodb.internal.crypt.capi.CAPI;
import com.mongodb.internal.crypt.capi.MongoCrypt;
import com.mongodb.internal.crypt.capi.MongoCryptContext;
import com.mongodb.internal.crypt.capi.MongoCryptOptions;
import com.mongodb.internal.crypt.capi.MongoCrypts;
import com.mongodb.internal.crypt.capi.MongoExplicitEncryptOptions;
import com.mongodb.internal.crypt.capi.MongoLocalKmsProviderOptions;
import org.bson.BsonBinary;
import org.bson.BsonBinarySubType;
import org.bson.BsonDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoConfigurationException;
import com.mongodb.client.model.vault.RewrapManyDataKeyOptions;
import com.mongodb.crypt.capi.MongoCryptOptions;
import com.mongodb.internal.authentication.AwsCredentialHelper;
import com.mongodb.internal.authentication.AzureCredentialHelper;
import com.mongodb.internal.authentication.GcpCredentialHelper;
import com.mongodb.internal.crypt.capi.MongoCryptOptions;
import com.mongodb.lang.Nullable;
import org.bson.BsonDocument;
import org.bson.BsonDocumentWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.mongodb.client.model.vault.EncryptOptions;
import com.mongodb.client.model.vault.RangeOptions;
import com.mongodb.crypt.capi.MongoExplicitEncryptOptions;
import com.mongodb.internal.crypt.capi.MongoExplicitEncryptOptions;
import org.bson.BsonDocument;
import org.bson.BsonInt32;
import org.bson.BsonInt64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.mongodb.MongoClientException;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.model.vault.RewrapManyDataKeyOptions;
import com.mongodb.crypt.capi.MongoCryptOptions;
import com.mongodb.internal.crypt.capi.MongoCryptOptions;
import org.bson.BsonDocument;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.crypt.capi.MongoCrypt;
import com.mongodb.internal.crypt.capi.MongoCrypt;
import com.mongodb.internal.time.Timeout;
import com.mongodb.lang.Nullable;
import com.mongodb.reactivestreams.client.MongoClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import com.mongodb.client.model.vault.DataKeyOptions;
import com.mongodb.client.model.vault.EncryptOptions;
import com.mongodb.client.model.vault.RewrapManyDataKeyOptions;
import com.mongodb.crypt.capi.MongoCrypt;
import com.mongodb.crypt.capi.MongoCryptContext;
import com.mongodb.crypt.capi.MongoCryptException;
import com.mongodb.crypt.capi.MongoDataKeyOptions;
import com.mongodb.crypt.capi.MongoKeyDecryptor;
import com.mongodb.crypt.capi.MongoRewrapManyDataKeyOptions;
import com.mongodb.internal.capi.MongoCryptHelper;
import com.mongodb.internal.crypt.capi.MongoCrypt;
import com.mongodb.internal.crypt.capi.MongoCryptContext;
import com.mongodb.internal.crypt.capi.MongoDataKeyOptions;
import com.mongodb.internal.crypt.capi.MongoKeyDecryptor;
import com.mongodb.internal.crypt.capi.MongoRewrapManyDataKeyOptions;
import com.mongodb.internal.diagnostics.logging.Logger;
import com.mongodb.internal.diagnostics.logging.Loggers;
import com.mongodb.internal.time.Timeout;
Expand All @@ -48,8 +48,8 @@
import java.util.function.Supplier;

import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.crypt.capi.MongoCryptContext.State;
import static com.mongodb.internal.client.vault.EncryptOptionsHelper.asMongoExplicitEncryptOptions;
import static com.mongodb.internal.crypt.capi.MongoCryptContext.State;

/**
* <p>This class is not part of the public API and may be removed or changed at any time</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.mongodb.MongoClientException;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoNamespace;
import com.mongodb.crypt.capi.MongoCrypt;
import com.mongodb.crypt.capi.MongoCrypts;
import com.mongodb.internal.crypt.capi.MongoCrypt;
import com.mongodb.internal.crypt.capi.MongoCrypts;
import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.mongodb.connection.AsyncCompletionHandler;
import com.mongodb.connection.SocketSettings;
import com.mongodb.connection.SslSettings;
import com.mongodb.crypt.capi.MongoKeyDecryptor;
import com.mongodb.internal.TimeoutContext;
import com.mongodb.internal.TimeoutSettings;
import com.mongodb.internal.connection.AsynchronousChannelStream;
Expand All @@ -33,6 +32,7 @@
import com.mongodb.internal.connection.Stream;
import com.mongodb.internal.connection.StreamFactory;
import com.mongodb.internal.connection.TlsChannelStreamFactoryFactory;
import com.mongodb.internal.crypt.capi.MongoKeyDecryptor;
import com.mongodb.internal.diagnostics.logging.Logger;
import com.mongodb.internal.diagnostics.logging.Loggers;
import com.mongodb.internal.time.Timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;
import com.mongodb.crypt.capi.MongoCrypt;
import com.mongodb.internal.crypt.capi.MongoCrypt;
import com.mongodb.internal.time.Timeout;
import com.mongodb.lang.Nullable;
import org.bson.RawBsonDocument;
Expand Down
12 changes: 6 additions & 6 deletions driver-sync/src/main/com/mongodb/client/internal/Crypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import com.mongodb.client.model.vault.DataKeyOptions;
import com.mongodb.client.model.vault.EncryptOptions;
import com.mongodb.client.model.vault.RewrapManyDataKeyOptions;
import com.mongodb.crypt.capi.MongoCrypt;
import com.mongodb.crypt.capi.MongoCryptContext;
import com.mongodb.crypt.capi.MongoCryptException;
import com.mongodb.crypt.capi.MongoDataKeyOptions;
import com.mongodb.crypt.capi.MongoKeyDecryptor;
import com.mongodb.crypt.capi.MongoRewrapManyDataKeyOptions;
import com.mongodb.internal.capi.MongoCryptHelper;
import com.mongodb.internal.crypt.capi.MongoCrypt;
import com.mongodb.internal.crypt.capi.MongoCryptContext;
import com.mongodb.internal.crypt.capi.MongoDataKeyOptions;
import com.mongodb.internal.crypt.capi.MongoKeyDecryptor;
import com.mongodb.internal.crypt.capi.MongoRewrapManyDataKeyOptions;
import com.mongodb.internal.time.Timeout;
import com.mongodb.lang.Nullable;
import org.bson.BsonBinary;
Expand All @@ -46,8 +46,8 @@

import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.crypt.capi.MongoCryptContext.State;
import static com.mongodb.internal.client.vault.EncryptOptionsHelper.asMongoExplicitEncryptOptions;
import static com.mongodb.internal.crypt.capi.MongoCryptContext.State;
import static com.mongodb.internal.thread.InterruptionUtil.translateInterruptedException;

/**
Expand Down
4 changes: 2 additions & 2 deletions driver-sync/src/main/com/mongodb/client/internal/Crypts.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.mongodb.MongoNamespace;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.crypt.capi.MongoCrypt;
import com.mongodb.crypt.capi.MongoCrypts;
import com.mongodb.internal.crypt.capi.MongoCrypt;
import com.mongodb.internal.crypt.capi.MongoCrypts;

import javax.net.ssl.SSLContext;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
package com.mongodb.crypt.capi;


import com.mongodb.crypt.capi.CAPI.mongocrypt_status_t;

import static com.mongodb.crypt.capi.CAPI.mongocrypt_status_code;
import static org.bson.assertions.Assertions.isTrue;

/**
* Top level Exception for all Mongo Crypt CAPI exceptions
* Exception thrown for errors originating in the mongodb-crypt module.
*/
public class MongoCryptException extends RuntimeException {
private static final long serialVersionUID = -5524416583514807953L;
private final int code;

/**
* Construct an instance
*
* @param message the message
* @param code the code
*/
public MongoCryptException(final String message, final int code) {
super(message);
this.code = code;
}

/**
* @param msg the message
*/
Expand All @@ -47,17 +53,6 @@ public MongoCryptException(final String msg, final Throwable cause) {
this.code = -1;
}

/**
* Construct an instance from a {@code mongocrypt_status_t}.
*
* @param status the status
*/
MongoCryptException(final mongocrypt_status_t status) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is not a breaking change because it's not public.

super(CAPI.mongocrypt_status_message(status, null).toString());
isTrue("status not ok", !CAPI.mongocrypt_status_ok(status));
code = mongocrypt_status_code(status);
}

/**
* @return the error code for the exception.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

import com.mongodb.crypt.capi.CAPI.mongocrypt_binary_t;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_binary_t;

import static com.mongodb.crypt.capi.CAPI.mongocrypt_binary_destroy;
import static com.mongodb.internal.crypt.capi.CAPI.mongocrypt_binary_destroy;

// Wrap JNA memory and a mongocrypt_binary_t that references that memory, in order to ensure that the JNA Memory is not GC'd before the
// mongocrypt_binary_t is destroyed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

import com.sun.jna.Callback;
import com.sun.jna.Memory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

import com.mongodb.crypt.capi.CAPI.mongocrypt_binary_t;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_binary_t;
import com.sun.jna.Pointer;
import org.bson.BsonBinaryWriter;
import org.bson.BsonDocument;
Expand All @@ -31,7 +31,7 @@

import java.nio.ByteBuffer;

import static com.mongodb.crypt.capi.CAPI.mongocrypt_binary_new_from_data;
import static com.mongodb.internal.crypt.capi.CAPI.mongocrypt_binary_new_from_data;
import static java.lang.String.format;

final class CAPIHelper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

import com.mongodb.crypt.capi.CAPI.cstring;
import com.mongodb.crypt.capi.CAPI.mongocrypt_binary_t;
import com.mongodb.crypt.capi.CAPI.mongocrypt_crypto_fn;
import com.mongodb.crypt.capi.CAPI.mongocrypt_status_t;
import com.mongodb.internal.crypt.capi.CAPI.cstring;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_binary_t;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_crypto_fn;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_status_t;
import com.sun.jna.Pointer;

import javax.crypto.Cipher;
Expand All @@ -30,10 +30,10 @@
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.ConcurrentLinkedDeque;

import static com.mongodb.crypt.capi.CAPI.MONGOCRYPT_STATUS_ERROR_CLIENT;
import static com.mongodb.crypt.capi.CAPI.mongocrypt_status_set;
import static com.mongodb.crypt.capi.CAPIHelper.toByteArray;
import static com.mongodb.crypt.capi.CAPIHelper.writeByteArrayToBinary;
import static com.mongodb.internal.crypt.capi.CAPI.MONGOCRYPT_STATUS_ERROR_CLIENT;
import static com.mongodb.internal.crypt.capi.CAPI.mongocrypt_status_set;
import static com.mongodb.internal.crypt.capi.CAPIHelper.toByteArray;
import static com.mongodb.internal.crypt.capi.CAPIHelper.writeByteArrayToBinary;

class CipherCallback implements mongocrypt_crypto_fn {
private final String algorithm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

import com.sun.jna.Memory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

import java.util.logging.Level;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

/**
* Not part of the public API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

/**
* This class is not part of the public API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

import com.mongodb.crypt.capi.CAPI.cstring;
import com.mongodb.crypt.capi.CAPI.mongocrypt_binary_t;
import com.mongodb.crypt.capi.CAPI.mongocrypt_hmac_fn;
import com.mongodb.crypt.capi.CAPI.mongocrypt_status_t;
import com.mongodb.internal.crypt.capi.CAPI.cstring;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_binary_t;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_hmac_fn;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_status_t;
import com.sun.jna.Pointer;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import static com.mongodb.crypt.capi.CAPI.MONGOCRYPT_STATUS_ERROR_CLIENT;
import static com.mongodb.crypt.capi.CAPI.mongocrypt_status_set;
import static com.mongodb.crypt.capi.CAPIHelper.toByteArray;
import static com.mongodb.crypt.capi.CAPIHelper.writeByteArrayToBinary;
import static com.mongodb.internal.crypt.capi.CAPI.MONGOCRYPT_STATUS_ERROR_CLIENT;
import static com.mongodb.internal.crypt.capi.CAPI.mongocrypt_status_set;
import static com.mongodb.internal.crypt.capi.CAPIHelper.toByteArray;
import static com.mongodb.internal.crypt.capi.CAPIHelper.writeByteArrayToBinary;

class MacCallback implements mongocrypt_hmac_fn {
private final String algorithm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
*
*/

package com.mongodb.crypt.capi;
package com.mongodb.internal.crypt.capi;

import com.mongodb.crypt.capi.CAPI.cstring;
import com.mongodb.crypt.capi.CAPI.mongocrypt_binary_t;
import com.mongodb.crypt.capi.CAPI.mongocrypt_hash_fn;
import com.mongodb.crypt.capi.CAPI.mongocrypt_status_t;
import com.mongodb.internal.crypt.capi.CAPI.cstring;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_binary_t;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_hash_fn;
import com.mongodb.internal.crypt.capi.CAPI.mongocrypt_status_t;
import com.sun.jna.Pointer;

import java.security.MessageDigest;

import static com.mongodb.crypt.capi.CAPI.MONGOCRYPT_STATUS_ERROR_CLIENT;
import static com.mongodb.crypt.capi.CAPI.mongocrypt_status_set;
import static com.mongodb.crypt.capi.CAPIHelper.toByteArray;
import static com.mongodb.crypt.capi.CAPIHelper.writeByteArrayToBinary;
import static com.mongodb.internal.crypt.capi.CAPI.MONGOCRYPT_STATUS_ERROR_CLIENT;
import static com.mongodb.internal.crypt.capi.CAPI.mongocrypt_status_set;
import static com.mongodb.internal.crypt.capi.CAPIHelper.toByteArray;
import static com.mongodb.internal.crypt.capi.CAPIHelper.writeByteArrayToBinary;

class MessageDigestCallback implements mongocrypt_hash_fn {

Expand Down
Loading