func (m *MongoCrypt) CreateDataKeyContext(kmsProvider string, opts *options.DataKeyOptions) (*Context, error) {
	ctx := newContext(C.mongocrypt_ctx_new(m.wrapped))
	if ctx.wrapped == nil {
		return nil, m.createErrorFromStatus()
	}

	var ok bool
	switch kmsProvider {
	case AwsProvider:
		// set region and key (required fields)
		region := C.CString(lookupString(opts.MasterKey, "region"))
		key := C.CString(lookupString(opts.MasterKey, "key"))
		defer C.free(unsafe.Pointer(region))
		defer C.free(unsafe.Pointer(key))
		ok = bool(C.mongocrypt_ctx_setopt_masterkey_aws(ctx.wrapped, region, -1, key, -1))
		if !ok {
			break
		}

		// set endpoint (not a required field)
		endpoint := lookupString(opts.MasterKey, "endpoint")
		if endpoint == "" {
			break
		}
		endpointCStr := C.CString(endpoint)
		defer C.free(unsafe.Pointer(endpointCStr))
		ok = bool(C.mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx.wrapped, endpointCStr, -1))
	case LocalProvider:
		ok = bool(C.mongocrypt_ctx_setopt_masterkey_local(ctx.wrapped))
	default:
		return nil, ErrInvalidProvider
	}
	if !ok {
		return nil, ctx.createErrorFromStatus()
	}

	for _, altName := range opts.KeyAltNames {
		if err := setAltName(ctx, altName); err != nil {
			return nil, err
		}
	}

	if ok := C.mongocrypt_ctx_datakey_init(ctx.wrapped); !ok {
		return nil, ctx.createErrorFromStatus()
	}
	return ctx, nil
}
// CreateDataKeyContext creates a Context to use for creating a data key.
CreateDataKeyContext creates a Context to use for creating a data key.
// CreateDataKeyContext creates a Context to use for creating a data key .
func (m *MongoCrypt) CreateDataKeyContext(kmsProvider string, opts *options.DataKeyOptions) (*Context, error) {
	ctx := newContext(C.mongocrypt_ctx_new(m.wrapped))
	if ctx.wrapped == nil {
		return nil, m.createErrorFromStatus()
	}
	var ok bool
	switch kmsProvider {
	case AwsProvider:
		region := C.CString(lookupString(opts.MasterKey, "region"))
		key := C.CString(lookupString(opts.MasterKey, "key"))
		defer C.free(unsafe.Pointer(region))
		defer C.free(unsafe.Pointer(key))
		ok = bool(C.mongocrypt_ctx_setopt_masterkey_aws(ctx.wrapped, region, -1, key, -1))
		if !ok {
			break
		}
		endpoint := lookupString(opts.MasterKey, "endpoint")
		if endpoint == "" {
			break
		}
		endpointCStr := C.CString(endpoint)
		defer C.free(unsafe.Pointer(endpointCStr))
		ok = bool(C.mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx.wrapped, endpointCStr, -1))
	case LocalProvider:
		ok = bool(C.mongocrypt_ctx_setopt_masterkey_local(ctx.wrapped))
	default:
		return nil, ErrInvalidProvider
	}
	if !ok {
		return nil, ctx.createErrorFromStatus()
	}
	for _, altName := range opts.KeyAltNames {
		if err := setAltName(ctx, altName); err != nil {
			return nil, err
		}
	}
	if ok := C.mongocrypt_ctx_datakey_init(ctx.wrapped); !ok {
		return nil, ctx.createErrorFromStatus()
	}
	return ctx, nil
}
func ( m * MongoCrypt ) CreateDataKeyContext ( kmsProvider string , opts * options . DataKeyOptions ) ( * Context , error ) { ctx := newContext ( C . mongocrypt_ctx_new ( m . wrapped ) ) if ctx . wrapped == nil { return nil , m . createErrorFromStatus ( ) } var ok bool switch kmsProvider { case AwsProvider : region := C . CString ( lookupString ( opts . MasterKey , " " ) ) key := C . CString ( lookupString ( opts . MasterKey , " " ) ) defer C . free ( unsafe . Pointer ( region ) ) defer C . free ( unsafe . Pointer ( key ) ) ok = bool ( C . mongocrypt_ctx_setopt_masterkey_aws ( ctx . wrapped , region , - 1 , key , - 1 ) ) if ! ok { break } endpoint := lookupString ( opts . MasterKey , " " ) if endpoint == " " { break } endpointCStr := C . CString ( endpoint ) defer C . free ( unsafe . Pointer ( endpointCStr ) ) ok = bool ( C . mongocrypt_ctx_setopt_masterkey_aws_endpoint ( ctx . wrapped , endpointCStr , - 1 ) ) case LocalProvider : ok = bool ( C . mongocrypt_ctx_setopt_masterkey_local ( ctx . wrapped ) ) default : return nil , ErrInvalidProvider } if ! ok { return nil , ctx . createErrorFromStatus ( ) } for _ , altName := range opts . KeyAltNames { if err := setAltName ( ctx , altName ) ; err != nil { return nil , err } } if ok := C . mongocrypt_ctx_datakey_init ( ctx . wrapped ) ; ! ok { return nil , ctx . createErrorFromStatus ( ) } return ctx , nil }
CreateDataKeyContext creates a Context to use for creating a data key.
CreateDataKeyContext creates a Context to use for creating a data key .
// set region and key (required fields) // set endpoint (not a required field)