/// <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));
        }
示例#2
0
        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));
                    }
                }
            }
        }