-
Notifications
You must be signed in to change notification settings - Fork 83
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
CSHARP-4944: Enable use of native crypto in libmongocrypt bindings #796
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor questions.
} | ||
catch (LibraryLoader.FunctionNotFoundException) | ||
{ | ||
// mongocrypt_is_crypto_available is only available in libmongocrypt version >= 1.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this better than checking the Library.Version
?
In the case when the version is right, and mongocrypt_is_crypto_available
throws, that might point to other problems, and then it's better to fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Done
@@ -186,10 +168,18 @@ private class LinuxLibrary : ISharedLibraryLoader | |||
// #define RTLD_GLOBAL 0x100 | |||
public const int RTLD_GLOBAL = 0x100; | |||
public const int RTLD_NOW = 0x2; | |||
|
|||
private static readonly string[] _suffixPaths = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plz add static prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments
@@ -42,14 +42,15 @@ public static CryptClient Create(CryptOptions options) | |||
MongoCryptSafeHandle handle = null; | |||
Status status = null; | |||
|
|||
// mongocrypt_is_crypto_available is only available in libmongocrypt version >= 1.9 | |||
var cryptoAvailable = Version.Parse(Library.Version) >= Version.Parse("1.9") && Library.mongocrypt_is_crypto_available(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: let's safe Version.Parse("1.9")
as static readonly var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
bindings/cs/README.md
Outdated
@@ -54,6 +54,9 @@ If you see `Windows Error: 126` during tests, like the example below, it means t | |||
2. cd <build>/bindings/cs | |||
3. dotnet build cs.build | |||
``` | |||
*Note*: You can use the ```LIBMONGOCRYPT_PATH``` environment variable to load a locally installed | |||
libmongocrypt build. You should specify the absolute path to the libmongocrypt build itself not just the containing folder. For example on Linux: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libmongocrypt build. You should specify the absolute path to the libmongocrypt build itself not just the containing folder. For example on Linux: | |
libmongocrypt build. You should specify the absolute path to the libmongocrypt library itself, not just the containing folder. For example on Linux: |
@@ -150,9 +124,17 @@ private class DarwinLibraryLoader : ISharedLibraryLoader | |||
public const int RTLD_GLOBAL = 0x8; | |||
public const int RTLD_NOW = 0x2; | |||
|
|||
private static readonly string[] _s_suffixPaths = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we are missing conventions for static vars, in libmongocrypt. Let's go with the usual ___s_suffixPaths
convention here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -34,6 +34,9 @@ public class CryptClientFactory | |||
private static Library.Delegates.RandomCallback __randomCallback = new Library.Delegates.RandomCallback(SecureRandomCallback.GenerateRandom); | |||
private static Library.Delegates.CryptoHmacCallback __signRsaesPkcs1HmacCallback = new Library.Delegates.CryptoHmacCallback(SigningRSAESPKCSCallback.RsaSign); | |||
|
|||
// mongocrypt_is_crypto_available is only available in libmongocrypt version >= 1.9 | |||
private static readonly Version __s_libVersionWithMongocryptIsCryptoAvailable = Version.Parse("1.9"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider:
private static readonly Version __mongocryptIsCryptoAvailableMinVersion = Version.Parse("1.9");
bindings/cs/README.md
Outdated
@@ -54,6 +54,9 @@ If you see `Windows Error: 126` during tests, like the example below, it means t | |||
2. cd <build>/bindings/cs | |||
3. dotnet build cs.build | |||
``` | |||
*Note*: You can use the ```LIBMONGOCRYPT_PATH``` environment variable to load a locally installed | |||
libmongocrypt build. You should specify the absolute path to the libmongocrypt library itself, not just the containing folder. For example on Linux: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment got lost:
#796 (comment)
@@ -150,9 +124,17 @@ private class DarwinLibraryLoader : ISharedLibraryLoader | |||
public const int RTLD_GLOBAL = 0x8; | |||
public const int RTLD_NOW = 0x2; | |||
|
|||
private static readonly string[] __s_suffixPaths = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry for confusion, I wanted to write __suffixPaths
instead ___s_suffixPaths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Use libmongocrypt native crypto when available.
What's changing
LIBMONGOCRYPT_PATH
to make it available to the driver. IfLIBMONGOCRYPT_PATH
is not set then we default to using the packaged crypto-disabled libmongocrypt.Performance Results
Using crypto-disabled libmongocrypt:
Using crypto-enabled libmongocrypt: