LoadBuckets(
            ValidatorRecipe recipe,
            Dictionary <String, Object> objectStorage)    // throws CertificateValidationException
        {
            foreach (CertificateBucketType certificateBucketType in recipe.CertificateBucket)
            {
                SimpleCertificateBucket certificateBucket = new SimpleCertificateBucket();

                foreach (CertificateBucketType_Group o in certificateBucketType.CertificateBucketType_Group)
                {
                    if (!string.IsNullOrWhiteSpace(o.Certificate))
                    {
                        certificateBucket.Add(Validator.GetCertificate(Convert.FromBase64String(o.Certificate)));
                    }
                    else if (o.CertificateReference != null)
                    {
                        CertificateReferenceType c = o.CertificateReference;
                        foreach (X509Certificate certificate in GetKeyStore(c.KeyStore, objectStorage).ToSimple(c.PrimitiveValue))
                        {
                            certificateBucket.Add(certificate);
                        }
                    }
                    else if (o.CertificateStartsWith != null)
                    {
                        CertificateStartsWithType c = o.CertificateStartsWith;
                        foreach (X509Certificate certificate in GetKeyStore(c.KeyStore, objectStorage).StartsWith(c.PrimitiveValue))
                        {
                            certificateBucket.Add(certificate);
                        }
                    }
                }

                objectStorage.Add($"#bucket::{certificateBucketType.Name}", certificateBucket);
            }
        }
        public static ValidatorGroup Parse(Stream inputStream, Dictionary <String, Object> objectStorage)
        {
            ValidatorRecipe recipe = new ValidatorRecipe(); // XmlTools.Read<ValidatorRecipe>(inputStream);

            recipe.FromXmlStream(inputStream);

            LoadKeyStores(recipe, objectStorage);
            LoadBuckets(recipe, objectStorage);

            Dictionary <String, IValidatorRule> rulesMap = new Dictionary <string, IValidatorRule>();

            foreach (ValidatorType validatorType in recipe.Validator)
            {
                var            rules         = validatorType.ExtensibleTypeData[0].ExtensibleType_Type_Group.ToList();
                IValidatorRule validatorRule = Parse(
                    rules,
                    objectStorage,
                    Enumerations.JunctionEnum.AND);

                if (validatorType.ValidatorTypeData.Timeout != null)
                {
                    validatorRule = new CachedValidatorRule(validatorRule);
                }

                String name = validatorType.ValidatorTypeData.Name == null ? "default" : validatorType.ValidatorTypeData.Name;
                rulesMap.Add(name, validatorRule);
                objectStorage.Add(String.Format("#validator::{0}", name), validatorRule);
            }

            return(new ValidatorGroup(rulesMap, recipe.Name, recipe.Version));
            //    } catch (JAXBException | CertificateValidationException e) {
            //                    throw new ValidatorParsingException(e.getMessage(), e);
            //}
        }
        LoadKeyStores(
            ValidatorRecipe recipe,
            Dictionary <String, Object> objectStorage)    // throws CertificateValidationException
        {
            foreach (KeyStoreType keyStoreType in recipe.KeyStore)
            {
                var key   = String.Format("#keyStore::{0}", keyStoreType.Name ?? "default");
                var value = new KeyStoreCertificateBucket(
                    Convert.FromBase64String(keyStoreType.PrimitiveValue.Base64Encoded).ToStream(),
                    keyStoreType.Password);

                objectStorage.Add(key, value);
            }
        }