...
1
2
3
4
5
6
7 package mongo
8
9 import (
10 "context"
11
12 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
13 )
14
15
16 type keyRetriever struct {
17 coll *Collection
18 }
19
20 func (kr *keyRetriever) cryptKeys(ctx context.Context, filter bsoncore.Document) ([]bsoncore.Document, error) {
21
22
23 ctx = NewSessionContext(ctx, nil)
24 cursor, err := kr.coll.Find(ctx, filter)
25 if err != nil {
26 return nil, EncryptionKeyVaultError{Wrapped: err}
27 }
28 defer cursor.Close(ctx)
29
30 var results []bsoncore.Document
31 for cursor.Next(ctx) {
32 cur := make([]byte, len(cursor.Current))
33 copy(cur, cursor.Current)
34 results = append(results, cur)
35 }
36 if err = cursor.Err(); err != nil {
37 return nil, EncryptionKeyVaultError{Wrapped: err}
38 }
39
40 return results, nil
41 }
42
43
44 type collInfoRetriever struct {
45 client *Client
46 }
47
48 func (cir *collInfoRetriever) cryptCollInfo(ctx context.Context, db string, filter bsoncore.Document) (bsoncore.Document, error) {
49
50
51 ctx = NewSessionContext(ctx, nil)
52 cursor, err := cir.client.Database(db).ListCollections(ctx, filter)
53 if err != nil {
54 return nil, err
55 }
56 defer cursor.Close(ctx)
57
58 if !cursor.Next(ctx) {
59 return nil, cursor.Err()
60 }
61
62 res := make([]byte, len(cursor.Current))
63 copy(res, cursor.Current)
64 return res, nil
65 }
66
View as plain text