github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/internal/csfle_util.go (about) 1 // Copyright (C) MongoDB, Inc. 2022-present. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 7 package internal 8 9 import ( 10 "fmt" 11 12 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore" 13 ) 14 15 const ( 16 EncryptedCacheCollection = "ecc" 17 EncryptedStateCollection = "esc" 18 EncryptedCompactionCollection = "ecoc" 19 ) 20 21 // GetEncryptedStateCollectionName returns the encrypted state collection name associated with dataCollectionName. 22 func GetEncryptedStateCollectionName(efBSON bsoncore.Document, dataCollectionName string, stateCollection string) (string, error) { 23 fieldName := stateCollection + "Collection" 24 val, err := efBSON.LookupErr(fieldName) 25 if err != nil { 26 if err != bsoncore.ErrElementNotFound { 27 return "", err 28 } 29 // Return default name. 30 defaultName := "enxcol_." + dataCollectionName + "." + stateCollection 31 return defaultName, nil 32 } 33 34 stateCollectionName, ok := val.StringValueOK() 35 if !ok { 36 return "", fmt.Errorf("expected string for '%v', got: %v", fieldName, val.Type) 37 } 38 return stateCollectionName, nil 39 }