public BouncyCastleServices(byte[] privateKey) { var fac = new DefaultFactories(); KeyAgreementFactory = fac; VerifierFactory = fac; AesFactory = fac; Signature = new Signature(new ArraySegment <byte>(privateKey)); }
/// <summary> /// Gets the matching factory for the given member. /// </summary> /// <exception cref="CreateInstanceException">Multiple matching factories found.</exception> /// <typeparam name="T">The type of the instance to create.</typeparam> /// <param name="options">Some create instance options.</param> /// <param name="memberInformation">The member to check.</param> /// <returns>Returns the matching factory, or null if no factory was found.</returns> private static IInstanceFactory GetExactlymatchingFactory <T>(ICreateInstanceOptionsComplete <T> options, IMemberInformation memberInformation) where T : class { // Get factory from options var matchingFactories = options.Factories.Where(x => RuleInspector.Inspect(x.SelectionRules, memberInformation) == MemberSelectionResult.IncludeMember) .ToList(); if (matchingFactories.Count == 1) { return(matchingFactories.Single()); } // Check if multiple factories have matched if (matchingFactories.Any()) { throw new CreateInstanceException( $"Found multiple matching factories for member (in options). Type is '{memberInformation.MemberType}'. Please make sure only one factory matches the member.", null, options.Factories.StringJoin(Environment.NewLine), null, memberInformation); } // Get factory from default factories matchingFactories = DefaultFactories.Where(x => RuleInspector.Inspect(x.SelectionRules, memberInformation) == MemberSelectionResult.IncludeMember) .ToList(); if (matchingFactories.Count == 1) { return(matchingFactories.Single()); } //Check if multiple factories have matched if (matchingFactories.Any()) { throw new CreateInstanceException( $"Found multiple matching factories for member (in global configuration). Type is '{memberInformation.MemberType}'. Please make sure only one factory matches the member.", null, DefaultFactories.StringJoin(Environment.NewLine), null, memberInformation); } // No factory found return(null); }
/// <summary> /// A factory method that creates an instance of <paramref name="{T}"/> using a public parameterless constructor. /// If no such constructor is found on <paramref name="{T}"/>, a <see cref="MissingMethodException"/> will be thrown. /// </summary> public static T CreateInstance <T>() { return(DefaultFactories <T> .Get()); }
/// <summary> /// Creates the default factories. /// </summary> private static void CreateDefaultFactories() => InstanceFactoryProvider.GetDefaultFactories() .ForEach(x => DefaultFactories.Add(x));