From 34603c323bdde187b24017c454ea5ac0ad3d565e Mon Sep 17 00:00:00 2001 From: Sergey Vilgelm Date: Thu, 10 Aug 2023 13:19:29 -0700 Subject: [PATCH] add interface for ClientEncryption Interface for mongo.ClientEncryption: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#ClientEncryption --- Makefile | 6 +- README.md | 1 + client.go | 17 +- client_encryption.go | 160 ++++++++++++++ mocks/gomock/mocks.go | 235 +++++++++++++++++++- mocks/mockery/client_encryption.go | 343 +++++++++++++++++++++++++++++ 6 files changed, 755 insertions(+), 7 deletions(-) create mode 100644 client_encryption.go create mode 100644 mocks/mockery/client_encryption.go diff --git a/Makefile b/Makefile index 93d7f09..14671ca 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ MONGO_USERNAME="admin" MONGO_PASSWORD="adminpass" MONGO_URI="mongodb://$(MONGO_USERNAME):$(MONGO_PASSWORD)@127.0.0.1:$(MONGO_PORT)/?authSource=admin&directConnection=true" -all: go-install generate-mocks tidy lint test done +all: go-install generate-mocks tidy test done done: @echo "$(OK_COLOR)==> Done.$(NO_COLOR)" @@ -49,10 +49,10 @@ lint: tidy: @echo "$(OK_COLOR)==> Updating go.mod...$(NO_COLOR)" - @go mod tidy -compat=1.19 + @go mod tidy -compat=1.21 run-mockgen: - @mockgen -destination=mocks/gomock/mocks.go -package mocks . ChangeStream,Client,Collection,Cursor,Database,IndexView,Session,SingleResult,SessionContext + @mockgen -destination=mocks/gomock/mocks.go -package mocks . ChangeStream,Client,Collection,Cursor,Database,IndexView,Session,SingleResult,SessionContext,ClientEncryption run-mockery: @mockery --all --srcpkg github.com/sv-tools/mongoifc --output mocks/mockery --disable-version-string --case underscore diff --git a/README.md b/README.md index d9cc4f1..abfab90 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ This is the main reason of wrapping the original objects and using the `mongoifc - [x] SingleResult: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#SingleResult - [x] IndexView: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#IndexView - [x] SessionContext: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#SessionContext +- [x] ClientEncryption: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#ClientEncryption ## Mocks diff --git a/client.go b/client.go index 34dd594..79615d6 100644 --- a/client.go +++ b/client.go @@ -15,7 +15,11 @@ type Client interface { Connect(ctx context.Context) error Database(name string, opts ...*options.DatabaseOptions) Database Disconnect(ctx context.Context) error - ListDatabaseNames(ctx context.Context, filter interface{}, opts ...*options.ListDatabasesOptions) ([]string, error) + ListDatabaseNames( + ctx context.Context, + filter interface{}, + opts ...*options.ListDatabasesOptions, + ) ([]string, error) ListDatabases( ctx context.Context, filter interface{}, @@ -25,8 +29,15 @@ type Client interface { Ping(ctx context.Context, rp *readpref.ReadPref) error StartSession(opts ...*options.SessionOptions) (Session, error) Timeout() *time.Duration - UseSession(ctx context.Context, fn func(sc SessionContext) error) error - UseSessionWithOptions(ctx context.Context, opts *options.SessionOptions, fn func(sc SessionContext) error) error + UseSession( + ctx context.Context, + fn func(sc SessionContext) error, + ) error + UseSessionWithOptions( + ctx context.Context, + opts *options.SessionOptions, + fn func(sc SessionContext) error, + ) error Watch( ctx context.Context, pipeline interface{}, diff --git a/client_encryption.go b/client_encryption.go new file mode 100644 index 0000000..f5b3704 --- /dev/null +++ b/client_encryption.go @@ -0,0 +1,160 @@ +package mongoifc + +import ( + "context" + + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" +) + +// ClientEncryption is an interface for `mongo.ClientEncryption` structure +// Documentation: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#ClientEncryption +type ClientEncryption interface { + AddKeyAltName( + ctx context.Context, + id primitive.Binary, + keyAltName string, + ) SingleResult + Close(ctx context.Context) error + CreateDataKey( + ctx context.Context, + kmsProvider string, + opts ...*options.DataKeyOptions, + ) (primitive.Binary, error) + CreateEncryptedCollection( + ctx context.Context, + db Database, + coll string, + createOpts *options.CreateCollectionOptions, + kmsProvider string, + masterKey interface{}, + ) (Collection, bson.M, error) + Decrypt(ctx context.Context, val primitive.Binary) (bson.RawValue, error) + DeleteKey(ctx context.Context, id primitive.Binary) (*mongo.DeleteResult, error) + Encrypt( + ctx context.Context, + val bson.RawValue, + opts ...*options.EncryptOptions, + ) (primitive.Binary, error) + EncryptExpression( + ctx context.Context, + expr interface{}, + result interface{}, + opts ...*options.EncryptOptions, + ) error + GetKey(ctx context.Context, id primitive.Binary) SingleResult + GetKeyByAltName(ctx context.Context, keyAltName string) SingleResult + GetKeys(ctx context.Context) (Cursor, error) + RemoveKeyAltName( + ctx context.Context, + id primitive.Binary, + keyAltName string, + ) SingleResult + RewrapManyDataKey( + ctx context.Context, + filter interface{}, + opts ...*options.RewrapManyDataKeyOptions, + ) (*mongo.RewrapManyDataKeyResult, error) +} + +type clientEncryption struct { + ce *mongo.ClientEncryption +} + +func (c *clientEncryption) AddKeyAltName(ctx context.Context, id primitive.Binary, keyAltName string) SingleResult { + return wrapSingleResult(c.ce.AddKeyAltName(ctx, id, keyAltName)) +} + +func (c *clientEncryption) Close(ctx context.Context) error { + return c.ce.Close(ctx) +} + +func (c *clientEncryption) CreateDataKey( + ctx context.Context, + kmsProvider string, + opts ...*options.DataKeyOptions, +) (primitive.Binary, error) { + return c.ce.CreateDataKey(ctx, kmsProvider, opts...) +} + +func (c *clientEncryption) CreateEncryptedCollection( + ctx context.Context, + db Database, + coll string, + createOpts *options.CreateCollectionOptions, + kmsProvider string, + masterKey interface{}, +) (Collection, bson.M, error) { + col, doc, err := c.ce.CreateEncryptedCollection(ctx, UnWrapDatabase(db), coll, createOpts, kmsProvider, masterKey) + if err != nil { + return nil, nil, err + } + return wrapCollection(col, db.(*database)), doc, err +} + +func (c *clientEncryption) Decrypt(ctx context.Context, val primitive.Binary) (bson.RawValue, error) { + return c.ce.Decrypt(ctx, val) +} + +func (c *clientEncryption) DeleteKey(ctx context.Context, id primitive.Binary) (*mongo.DeleteResult, error) { + return c.ce.DeleteKey(ctx, id) +} + +func (c *clientEncryption) Encrypt( + ctx context.Context, + val bson.RawValue, + opts ...*options.EncryptOptions, +) (primitive.Binary, error) { + return c.ce.Encrypt(ctx, val, opts...) +} + +func (c *clientEncryption) EncryptExpression( + ctx context.Context, + expr interface{}, + result interface{}, + opts ...*options.EncryptOptions, +) error { + return c.ce.EncryptExpression(ctx, expr, result, opts...) +} + +func (c *clientEncryption) GetKey(ctx context.Context, id primitive.Binary) SingleResult { + return wrapSingleResult(c.ce.GetKey(ctx, id)) +} + +func (c *clientEncryption) GetKeyByAltName(ctx context.Context, keyAltName string) SingleResult { + return wrapSingleResult(c.ce.GetKeyByAltName(ctx, keyAltName)) +} + +func (c *clientEncryption) GetKeys(ctx context.Context) (Cursor, error) { + cr, err := c.ce.GetKeys(ctx) + if err != nil { + return nil, err + } + return wrapCursor(cr), nil +} + +func (c *clientEncryption) RemoveKeyAltName( + ctx context.Context, + id primitive.Binary, + keyAltName string, +) SingleResult { + return wrapSingleResult(c.ce.RemoveKeyAltName(ctx, id, keyAltName)) +} + +func (c *clientEncryption) RewrapManyDataKey( + ctx context.Context, + filter interface{}, + opts ...*options.RewrapManyDataKeyOptions, +) (*mongo.RewrapManyDataKeyResult, error) { + return c.ce.RewrapManyDataKey(ctx, filter, opts...) +} + +func NewClientEncryption(keyVaultClient Client, opts ...*options.ClientEncryptionOptions) (ClientEncryption, error) { + ce, err := mongo.NewClientEncryption(UnWrapClient(keyVaultClient), opts...) + if err != nil { + return nil, err + } + return &clientEncryption{ce: ce}, nil +} diff --git a/mocks/gomock/mocks.go b/mocks/gomock/mocks.go index 9b38c4c..fc79cf4 100644 --- a/mocks/gomock/mocks.go +++ b/mocks/gomock/mocks.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/sv-tools/mongoifc (interfaces: ChangeStream,Client,Collection,Cursor,Database,IndexView,Session,SingleResult,SessionContext) +// Source: github.com/sv-tools/mongoifc (interfaces: ChangeStream,Client,Collection,Cursor,Database,IndexView,Session,SingleResult,SessionContext,ClientEncryption) // Package mocks is a generated GoMock package. package mocks @@ -1959,3 +1959,236 @@ func (mr *MockSessionContextMockRecorder) WithTransaction(arg0, arg1 interface{} varargs := append([]interface{}{arg0, arg1}, arg2...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithTransaction", reflect.TypeOf((*MockSessionContext)(nil).WithTransaction), varargs...) } + +// MockClientEncryption is a mock of ClientEncryption interface. +type MockClientEncryption struct { + ctrl *gomock.Controller + recorder *MockClientEncryptionMockRecorder +} + +// MockClientEncryptionMockRecorder is the mock recorder for MockClientEncryption. +type MockClientEncryptionMockRecorder struct { + mock *MockClientEncryption +} + +// NewMockClientEncryption creates a new mock instance. +func NewMockClientEncryption(ctrl *gomock.Controller) *MockClientEncryption { + mock := &MockClientEncryption{ctrl: ctrl} + mock.recorder = &MockClientEncryptionMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClientEncryption) EXPECT() *MockClientEncryptionMockRecorder { + return m.recorder +} + +// AddKeyAltName mocks base method. +func (m *MockClientEncryption) AddKeyAltName(arg0 context.Context, arg1 primitive.Binary, arg2 string) mongoifc.SingleResult { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddKeyAltName", arg0, arg1, arg2) + ret0, _ := ret[0].(mongoifc.SingleResult) + return ret0 +} + +// AddKeyAltName indicates an expected call of AddKeyAltName. +func (mr *MockClientEncryptionMockRecorder) AddKeyAltName(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddKeyAltName", reflect.TypeOf((*MockClientEncryption)(nil).AddKeyAltName), arg0, arg1, arg2) +} + +// Close mocks base method. +func (m *MockClientEncryption) Close(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Close", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Close indicates an expected call of Close. +func (mr *MockClientEncryptionMockRecorder) Close(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockClientEncryption)(nil).Close), arg0) +} + +// CreateDataKey mocks base method. +func (m *MockClientEncryption) CreateDataKey(arg0 context.Context, arg1 string, arg2 ...*options.DataKeyOptions) (primitive.Binary, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "CreateDataKey", varargs...) + ret0, _ := ret[0].(primitive.Binary) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateDataKey indicates an expected call of CreateDataKey. +func (mr *MockClientEncryptionMockRecorder) CreateDataKey(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateDataKey", reflect.TypeOf((*MockClientEncryption)(nil).CreateDataKey), varargs...) +} + +// CreateEncryptedCollection mocks base method. +func (m *MockClientEncryption) CreateEncryptedCollection(arg0 context.Context, arg1 mongoifc.Database, arg2 string, arg3 *options.CreateCollectionOptions, arg4 string, arg5 interface{}) (mongoifc.Collection, primitive.M, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateEncryptedCollection", arg0, arg1, arg2, arg3, arg4, arg5) + ret0, _ := ret[0].(mongoifc.Collection) + ret1, _ := ret[1].(primitive.M) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// CreateEncryptedCollection indicates an expected call of CreateEncryptedCollection. +func (mr *MockClientEncryptionMockRecorder) CreateEncryptedCollection(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateEncryptedCollection", reflect.TypeOf((*MockClientEncryption)(nil).CreateEncryptedCollection), arg0, arg1, arg2, arg3, arg4, arg5) +} + +// Decrypt mocks base method. +func (m *MockClientEncryption) Decrypt(arg0 context.Context, arg1 primitive.Binary) (bson.RawValue, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Decrypt", arg0, arg1) + ret0, _ := ret[0].(bson.RawValue) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Decrypt indicates an expected call of Decrypt. +func (mr *MockClientEncryptionMockRecorder) Decrypt(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Decrypt", reflect.TypeOf((*MockClientEncryption)(nil).Decrypt), arg0, arg1) +} + +// DeleteKey mocks base method. +func (m *MockClientEncryption) DeleteKey(arg0 context.Context, arg1 primitive.Binary) (*mongo.DeleteResult, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteKey", arg0, arg1) + ret0, _ := ret[0].(*mongo.DeleteResult) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DeleteKey indicates an expected call of DeleteKey. +func (mr *MockClientEncryptionMockRecorder) DeleteKey(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteKey", reflect.TypeOf((*MockClientEncryption)(nil).DeleteKey), arg0, arg1) +} + +// Encrypt mocks base method. +func (m *MockClientEncryption) Encrypt(arg0 context.Context, arg1 bson.RawValue, arg2 ...*options.EncryptOptions) (primitive.Binary, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Encrypt", varargs...) + ret0, _ := ret[0].(primitive.Binary) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Encrypt indicates an expected call of Encrypt. +func (mr *MockClientEncryptionMockRecorder) Encrypt(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Encrypt", reflect.TypeOf((*MockClientEncryption)(nil).Encrypt), varargs...) +} + +// EncryptExpression mocks base method. +func (m *MockClientEncryption) EncryptExpression(arg0 context.Context, arg1, arg2 interface{}, arg3 ...*options.EncryptOptions) error { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "EncryptExpression", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// EncryptExpression indicates an expected call of EncryptExpression. +func (mr *MockClientEncryptionMockRecorder) EncryptExpression(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EncryptExpression", reflect.TypeOf((*MockClientEncryption)(nil).EncryptExpression), varargs...) +} + +// GetKey mocks base method. +func (m *MockClientEncryption) GetKey(arg0 context.Context, arg1 primitive.Binary) mongoifc.SingleResult { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetKey", arg0, arg1) + ret0, _ := ret[0].(mongoifc.SingleResult) + return ret0 +} + +// GetKey indicates an expected call of GetKey. +func (mr *MockClientEncryptionMockRecorder) GetKey(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKey", reflect.TypeOf((*MockClientEncryption)(nil).GetKey), arg0, arg1) +} + +// GetKeyByAltName mocks base method. +func (m *MockClientEncryption) GetKeyByAltName(arg0 context.Context, arg1 string) mongoifc.SingleResult { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetKeyByAltName", arg0, arg1) + ret0, _ := ret[0].(mongoifc.SingleResult) + return ret0 +} + +// GetKeyByAltName indicates an expected call of GetKeyByAltName. +func (mr *MockClientEncryptionMockRecorder) GetKeyByAltName(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKeyByAltName", reflect.TypeOf((*MockClientEncryption)(nil).GetKeyByAltName), arg0, arg1) +} + +// GetKeys mocks base method. +func (m *MockClientEncryption) GetKeys(arg0 context.Context) (mongoifc.Cursor, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetKeys", arg0) + ret0, _ := ret[0].(mongoifc.Cursor) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetKeys indicates an expected call of GetKeys. +func (mr *MockClientEncryptionMockRecorder) GetKeys(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKeys", reflect.TypeOf((*MockClientEncryption)(nil).GetKeys), arg0) +} + +// RemoveKeyAltName mocks base method. +func (m *MockClientEncryption) RemoveKeyAltName(arg0 context.Context, arg1 primitive.Binary, arg2 string) mongoifc.SingleResult { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveKeyAltName", arg0, arg1, arg2) + ret0, _ := ret[0].(mongoifc.SingleResult) + return ret0 +} + +// RemoveKeyAltName indicates an expected call of RemoveKeyAltName. +func (mr *MockClientEncryptionMockRecorder) RemoveKeyAltName(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveKeyAltName", reflect.TypeOf((*MockClientEncryption)(nil).RemoveKeyAltName), arg0, arg1, arg2) +} + +// RewrapManyDataKey mocks base method. +func (m *MockClientEncryption) RewrapManyDataKey(arg0 context.Context, arg1 interface{}, arg2 ...*options.RewrapManyDataKeyOptions) (*mongo.RewrapManyDataKeyResult, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "RewrapManyDataKey", varargs...) + ret0, _ := ret[0].(*mongo.RewrapManyDataKeyResult) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RewrapManyDataKey indicates an expected call of RewrapManyDataKey. +func (mr *MockClientEncryptionMockRecorder) RewrapManyDataKey(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RewrapManyDataKey", reflect.TypeOf((*MockClientEncryption)(nil).RewrapManyDataKey), varargs...) +} diff --git a/mocks/mockery/client_encryption.go b/mocks/mockery/client_encryption.go new file mode 100644 index 0000000..7340e5f --- /dev/null +++ b/mocks/mockery/client_encryption.go @@ -0,0 +1,343 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + bson "go.mongodb.org/mongo-driver/bson" + + mock "github.com/stretchr/testify/mock" + + mongo "go.mongodb.org/mongo-driver/mongo" + + mongoifc "github.com/sv-tools/mongoifc" + + options "go.mongodb.org/mongo-driver/mongo/options" + + primitive "go.mongodb.org/mongo-driver/bson/primitive" +) + +// ClientEncryption is an autogenerated mock type for the ClientEncryption type +type ClientEncryption struct { + mock.Mock +} + +// AddKeyAltName provides a mock function with given fields: ctx, id, keyAltName +func (_m *ClientEncryption) AddKeyAltName(ctx context.Context, id primitive.Binary, keyAltName string) mongoifc.SingleResult { + ret := _m.Called(ctx, id, keyAltName) + + var r0 mongoifc.SingleResult + if rf, ok := ret.Get(0).(func(context.Context, primitive.Binary, string) mongoifc.SingleResult); ok { + r0 = rf(ctx, id, keyAltName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mongoifc.SingleResult) + } + } + + return r0 +} + +// Close provides a mock function with given fields: ctx +func (_m *ClientEncryption) Close(ctx context.Context) error { + ret := _m.Called(ctx) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CreateDataKey provides a mock function with given fields: ctx, kmsProvider, opts +func (_m *ClientEncryption) CreateDataKey(ctx context.Context, kmsProvider string, opts ...*options.DataKeyOptions) (primitive.Binary, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, kmsProvider) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 primitive.Binary + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, ...*options.DataKeyOptions) (primitive.Binary, error)); ok { + return rf(ctx, kmsProvider, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, string, ...*options.DataKeyOptions) primitive.Binary); ok { + r0 = rf(ctx, kmsProvider, opts...) + } else { + r0 = ret.Get(0).(primitive.Binary) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, ...*options.DataKeyOptions) error); ok { + r1 = rf(ctx, kmsProvider, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateEncryptedCollection provides a mock function with given fields: ctx, db, coll, createOpts, kmsProvider, masterKey +func (_m *ClientEncryption) CreateEncryptedCollection(ctx context.Context, db mongoifc.Database, coll string, createOpts *options.CreateCollectionOptions, kmsProvider string, masterKey interface{}) (mongoifc.Collection, primitive.M, error) { + ret := _m.Called(ctx, db, coll, createOpts, kmsProvider, masterKey) + + var r0 mongoifc.Collection + var r1 primitive.M + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, mongoifc.Database, string, *options.CreateCollectionOptions, string, interface{}) (mongoifc.Collection, primitive.M, error)); ok { + return rf(ctx, db, coll, createOpts, kmsProvider, masterKey) + } + if rf, ok := ret.Get(0).(func(context.Context, mongoifc.Database, string, *options.CreateCollectionOptions, string, interface{}) mongoifc.Collection); ok { + r0 = rf(ctx, db, coll, createOpts, kmsProvider, masterKey) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mongoifc.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, mongoifc.Database, string, *options.CreateCollectionOptions, string, interface{}) primitive.M); ok { + r1 = rf(ctx, db, coll, createOpts, kmsProvider, masterKey) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(primitive.M) + } + } + + if rf, ok := ret.Get(2).(func(context.Context, mongoifc.Database, string, *options.CreateCollectionOptions, string, interface{}) error); ok { + r2 = rf(ctx, db, coll, createOpts, kmsProvider, masterKey) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// Decrypt provides a mock function with given fields: ctx, val +func (_m *ClientEncryption) Decrypt(ctx context.Context, val primitive.Binary) (bson.RawValue, error) { + ret := _m.Called(ctx, val) + + var r0 bson.RawValue + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, primitive.Binary) (bson.RawValue, error)); ok { + return rf(ctx, val) + } + if rf, ok := ret.Get(0).(func(context.Context, primitive.Binary) bson.RawValue); ok { + r0 = rf(ctx, val) + } else { + r0 = ret.Get(0).(bson.RawValue) + } + + if rf, ok := ret.Get(1).(func(context.Context, primitive.Binary) error); ok { + r1 = rf(ctx, val) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteKey provides a mock function with given fields: ctx, id +func (_m *ClientEncryption) DeleteKey(ctx context.Context, id primitive.Binary) (*mongo.DeleteResult, error) { + ret := _m.Called(ctx, id) + + var r0 *mongo.DeleteResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, primitive.Binary) (*mongo.DeleteResult, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, primitive.Binary) *mongo.DeleteResult); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*mongo.DeleteResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, primitive.Binary) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Encrypt provides a mock function with given fields: ctx, val, opts +func (_m *ClientEncryption) Encrypt(ctx context.Context, val bson.RawValue, opts ...*options.EncryptOptions) (primitive.Binary, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, val) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 primitive.Binary + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, bson.RawValue, ...*options.EncryptOptions) (primitive.Binary, error)); ok { + return rf(ctx, val, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, bson.RawValue, ...*options.EncryptOptions) primitive.Binary); ok { + r0 = rf(ctx, val, opts...) + } else { + r0 = ret.Get(0).(primitive.Binary) + } + + if rf, ok := ret.Get(1).(func(context.Context, bson.RawValue, ...*options.EncryptOptions) error); ok { + r1 = rf(ctx, val, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// EncryptExpression provides a mock function with given fields: ctx, expr, result, opts +func (_m *ClientEncryption) EncryptExpression(ctx context.Context, expr interface{}, result interface{}, opts ...*options.EncryptOptions) error { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, expr, result) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, interface{}, ...*options.EncryptOptions) error); ok { + r0 = rf(ctx, expr, result, opts...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetKey provides a mock function with given fields: ctx, id +func (_m *ClientEncryption) GetKey(ctx context.Context, id primitive.Binary) mongoifc.SingleResult { + ret := _m.Called(ctx, id) + + var r0 mongoifc.SingleResult + if rf, ok := ret.Get(0).(func(context.Context, primitive.Binary) mongoifc.SingleResult); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mongoifc.SingleResult) + } + } + + return r0 +} + +// GetKeyByAltName provides a mock function with given fields: ctx, keyAltName +func (_m *ClientEncryption) GetKeyByAltName(ctx context.Context, keyAltName string) mongoifc.SingleResult { + ret := _m.Called(ctx, keyAltName) + + var r0 mongoifc.SingleResult + if rf, ok := ret.Get(0).(func(context.Context, string) mongoifc.SingleResult); ok { + r0 = rf(ctx, keyAltName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mongoifc.SingleResult) + } + } + + return r0 +} + +// GetKeys provides a mock function with given fields: ctx +func (_m *ClientEncryption) GetKeys(ctx context.Context) (mongoifc.Cursor, error) { + ret := _m.Called(ctx) + + var r0 mongoifc.Cursor + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (mongoifc.Cursor, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) mongoifc.Cursor); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mongoifc.Cursor) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// RemoveKeyAltName provides a mock function with given fields: ctx, id, keyAltName +func (_m *ClientEncryption) RemoveKeyAltName(ctx context.Context, id primitive.Binary, keyAltName string) mongoifc.SingleResult { + ret := _m.Called(ctx, id, keyAltName) + + var r0 mongoifc.SingleResult + if rf, ok := ret.Get(0).(func(context.Context, primitive.Binary, string) mongoifc.SingleResult); ok { + r0 = rf(ctx, id, keyAltName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mongoifc.SingleResult) + } + } + + return r0 +} + +// RewrapManyDataKey provides a mock function with given fields: ctx, filter, opts +func (_m *ClientEncryption) RewrapManyDataKey(ctx context.Context, filter interface{}, opts ...*options.RewrapManyDataKeyOptions) (*mongo.RewrapManyDataKeyResult, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, filter) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *mongo.RewrapManyDataKeyResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.RewrapManyDataKeyOptions) (*mongo.RewrapManyDataKeyResult, error)); ok { + return rf(ctx, filter, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.RewrapManyDataKeyOptions) *mongo.RewrapManyDataKeyResult); ok { + r0 = rf(ctx, filter, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*mongo.RewrapManyDataKeyResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.RewrapManyDataKeyOptions) error); ok { + r1 = rf(ctx, filter, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewClientEncryption creates a new instance of ClientEncryption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewClientEncryption(t interface { + mock.TestingT + Cleanup(func()) +}) *ClientEncryption { + mock := &ClientEncryption{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}