...
1
2
3
4
5
6
7 package csfle
8
9 import (
10 "errors"
11 "fmt"
12
13 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
14 )
15
16 const (
17 EncryptedCacheCollection = "ecc"
18 EncryptedStateCollection = "esc"
19 EncryptedCompactionCollection = "ecoc"
20 )
21
22
23 func GetEncryptedStateCollectionName(efBSON bsoncore.Document, dataCollectionName string, stateCollection string) (string, error) {
24 fieldName := stateCollection + "Collection"
25 val, err := efBSON.LookupErr(fieldName)
26 if err != nil {
27 if !errors.Is(err, bsoncore.ErrElementNotFound) {
28 return "", err
29 }
30
31 defaultName := "enxcol_." + dataCollectionName + "." + stateCollection
32 return defaultName, nil
33 }
34
35 stateCollectionName, ok := val.StringValueOK()
36 if !ok {
37 return "", fmt.Errorf("expected string for '%v', got: %v", fieldName, val.Type)
38 }
39 return stateCollectionName, nil
40 }
41
View as plain text