Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2747

Use Either monad to back KMSProviders

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Field Level Encryption
    • None

      Currently our KMS providers are backed with a  IReadOnlyDictionary<string, IReadOnlyDictionary<string, object>>

      We use the following method to ensure that the values in the subdictionaries are strings or byte arrays.

      public static void EnsureKmsProvidersAreValid(IReadOnlyDictionary<string, IReadOnlyDictionary<string, object>> kmsProviders)
      {
          foreach (var kmsProvider in kmsProviders)
          {
              foreach (var option in Ensure.IsNotNull(kmsProvider.Value, nameof(kmsProvider)))
              {
                  var optionValue = Ensure.IsNotNull(option.Value, "kmsProviderOption");
                  var isValid = optionValue is byte[] || optionValue is string;
                  if (!isValid)
                  {
                      throw new ArgumentException($"Invalid kms provider option type: {optionValue.GetType().Name}.");
                  }
              }
          }
      }
      

      We could make this restriction more explicit by using the Either monadto back the KMS providers internally:

      IReadOnlyDictionary<string, IReadOnlyDictionary<string, Either<string, byte[]>>

            Assignee:
            Unassigned Unassigned
            Reporter:
            vincent.kam@mongodb.com Vincent Kam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: