NServiceBus.RijndaelEncryptionServiceConfigValidations.ConfigurationHasDuplicateKeyIdentifiers C# (CSharp) Method

ConfigurationHasDuplicateKeyIdentifiers() public static method

public static ConfigurationHasDuplicateKeyIdentifiers ( RijndaelEncryptionServiceConfig section ) : bool
section RijndaelEncryptionServiceConfig
return bool
        public static bool ConfigurationHasDuplicateKeyIdentifiers(RijndaelEncryptionServiceConfig section)
        {
            // Combine all key identifier values, filter the empty ones, split them
            return section
                .ExpiredKeys
                .Cast<RijndaelExpiredKey>()
                .Select(x => x.KeyIdentifier)
                .Union(new[]
                {
                    section.KeyIdentifier
                })
                .Where(x => !string.IsNullOrEmpty(x))
                .Select(x => x.Split(';'))
                .SelectMany(x => x)
                .GroupBy(x => x)
                .Any(x => x.Count() > 1);
        }

Usage Example

Example #1
0
 internal static void ValidateConfigSection(RijndaelEncryptionServiceConfig section)
 {
     if (section == null)
     {
         throw new Exception("No RijndaelEncryptionServiceConfig defined. Specify a valid 'RijndaelEncryptionServiceConfig' in the application's configuration file.");
     }
     if (section.ExpiredKeys == null)
     {
         throw new Exception("RijndaelEncryptionServiceConfig.ExpiredKeys is null.");
     }
     if (string.IsNullOrWhiteSpace(section.Key))
     {
         throw new Exception("The RijndaelEncryptionServiceConfig has an empty 'Key' property.");
     }
     if (RijndaelEncryptionServiceConfigValidations.ExpiredKeysHaveWhiteSpace(section))
     {
         throw new Exception("The RijndaelEncryptionServiceConfig has a 'ExpiredKeys' property defined however some keys have no 'Key' property set.");
     }
     if (RijndaelEncryptionServiceConfigValidations.OneOrMoreExpiredKeysHaveNoKeyIdentifier(section))
     {
         Log.Warn("The RijndaelEncryptionServiceConfig has a 'ExpiredKeys' property defined however some keys have no 'KeyIdentifier' property value. Verify if this is intentional.");
     }
     if (RijndaelEncryptionServiceConfigValidations.EncryptionKeyListedInExpiredKeys(section))
     {
         throw new Exception("The RijndaelEncryptionServiceConfig has a 'Key' that is also defined inside the 'ExpiredKeys'.");
     }
     if (RijndaelEncryptionServiceConfigValidations.ExpiredKeysHaveDuplicateKeys(section))
     {
         throw new Exception("The RijndaelEncryptionServiceConfig has overlapping ExpiredKeys defined. Ensure that no keys overlap in the 'ExpiredKeys' property.");
     }
     if (RijndaelEncryptionServiceConfigValidations.ConfigurationHasDuplicateKeyIdentifiers(section))
     {
         throw new Exception("The RijndaelEncryptionServiceConfig has duplicate KeyIdentifiers defined with the same key identifier. Key identifiers must be unique in the complete configuration section.");
     }
 }