...

Source file src/go.mongodb.org/mongo-driver/internal/csfle/csfle.go

Documentation: go.mongodb.org/mongo-driver/internal/csfle

     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 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  // GetEncryptedStateCollectionName returns the encrypted state collection name associated with dataCollectionName.
    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  		// Return default name.
    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