/// <summary>Creates a CryptClient with the specified options.</summary>
        /// <param name="options">The options.</param>
        /// <returns>A CryptClient</returns>
        public static CryptClient Create(CryptOptions options)
        {
            MongoCryptSafeHandle handle = Library.mongocrypt_new();

            Status status = new Status();

            foreach (var kmsCredentials in options.KmsCredentialsMap)
            {
                ((IInternalKmsCredentials)kmsCredentials.Value).SetCredentials(handle, status);
            }

            if (options.Schema != null)
            {
                unsafe
                {
                    fixed(byte *schema = options.Schema)
                    {
                        var schemaPtr = (IntPtr)schema;

                        using (var pinnedSchema = new PinnedBinary(schemaPtr, (uint)options.Schema.Length))
                        {
                            handle.Check(status, Library.mongocrypt_setopt_schema_map(handle, schema: pinnedSchema.Handle));
                        }
                    }
                }
            }
            Library.mongocrypt_init(handle);

            return(new CryptClient(handle, status));
        }
Exemplo n.º 2
0
        // internal methods
        internal void SetCredentials(MongoCryptSafeHandle handle, Status status)
        {
            unsafe
            {
                fixed(byte *p = _credentialsBytes)
                {
                    IntPtr ptr = (IntPtr)p;

                    using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)_credentialsBytes.Length))
                    {
                        handle.Check(status, Library.mongocrypt_setopt_kms_providers(handle, pinned.Handle));
                    }
                }
            }
        }
        void IInternalKmsCredentials.SetCredentials(MongoCryptSafeHandle handle, Status status)
        {
            unsafe
            {
                fixed(byte *p = Key)
                {
                    IntPtr ptr = (IntPtr)p;

                    using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)Key.Length))
                    {
                        handle.Check(status, Library.mongocrypt_setopt_kms_provider_local(handle, pinned.Handle));
                    }
                }
            }
        }
Exemplo n.º 4
0
 internal CryptClient(MongoCryptSafeHandle handle, Status status)
 {
     _handle = handle;
     _status = status;
 }