private static string GetKmsKeyIdFromMetadata()

in src/Internal/SetupDecryptionHandlerV1.cs [46:72]


        private static string GetKmsKeyIdFromMetadata(MetadataCollection metadata)
        {
            var materialDescriptionJsonString = metadata[EncryptionUtils.XAmzMatDesc];
            if (materialDescriptionJsonString == null)
            {
                throw new InvalidDataException( $"{KMSKeyIDMetadataMessage} The key '{EncryptionUtils.XAmzMatDesc}' is missing.");
            }
            else
            {
                Dictionary<string,string> materialDescriptionJsonData;
                try
                {
                    materialDescriptionJsonData = JsonUtils.ToDictionary(materialDescriptionJsonString);
                }
                catch (InvalidDataException e)
                {
                    throw new InvalidDataException($"{KMSKeyIDMetadataMessage} The key '{EncryptionUtils.XAmzMatDesc}' does not contain valid JSON.", e);
                }

                if (!materialDescriptionJsonData.TryGetValue(EncryptionUtils.KMSCmkIDKey, out var kmsKeyIDJsonData))
                {
                    throw new InvalidDataException($"{KMSKeyIDMetadataMessage} The key '{kmsKeyIDJsonData}' is missing from the material description.");
                }

                return kmsKeyIDJsonData.ToString();
            }
        }