internal static object GetAlgorithmFromConfig(string algorithm) { if (string.IsNullOrEmpty(algorithm)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(algorithm))); } object algorithmObject = null; object defaultObject = null; Func <object> delegateFunction = null; if (!s_algorithmDelegateDictionary.TryGetValue(algorithm, out delegateFunction)) { lock (s_algorithmDictionaryLock) { if (!s_algorithmDelegateDictionary.ContainsKey(algorithm)) { try { algorithmObject = CryptoConfig.CreateFromName(algorithm); } catch (TargetInvocationException) { s_algorithmDelegateDictionary[algorithm] = null; } if (algorithmObject == null) { s_algorithmDelegateDictionary[algorithm] = null; } else { defaultObject = GetDefaultAlgorithm(algorithm); if (defaultObject != null && defaultObject.GetType() == algorithmObject.GetType()) { s_algorithmDelegateDictionary[algorithm] = null; } else { // Create a factory delegate which returns new instances of the algorithm type for later calls. Type algorithmType = algorithmObject.GetType(); Linq.Expressions.NewExpression algorithmCreationExpression = Linq.Expressions.Expression.New(algorithmType); Linq.Expressions.LambdaExpression creationFunction = Linq.Expressions.Expression.Lambda <Func <object> >(algorithmCreationExpression); delegateFunction = creationFunction.Compile() as Func <object>; if (delegateFunction != null) { s_algorithmDelegateDictionary[algorithm] = delegateFunction; } return(algorithmObject); } } } } } else { if (delegateFunction != null) { return(delegateFunction.Invoke()); } } // // This is a fallback in case CryptoConfig fails to return a valid // algorithm object. CrytoConfig does not understand all the uri's and // can return a null in that case, in which case it is our responsibility // to fallback and create the right algorithm if it is a uri we understand // switch (algorithm) { case SHA256String: case SecurityAlgorithms.Sha256Digest: return(SHA256.Create()); case SecurityAlgorithms.Sha1Digest: #pragma warning disable CA5350 // Do not use insecure cryptographic algorithm SHA1. return(SHA1.Create()); #pragma warning restore CA5350 // Do not use insecure cryptographic algorithm SHA1. case SecurityAlgorithms.HmacSha1Signature: #pragma warning disable CA5350 // Do not use insecure cryptographic algorithm SHA1. return(new HMACSHA1()); #pragma warning restore CA5350 // Do not use insecure cryptographic algorithm SHA1. default: break; } return(null); }
public override object DoAggregatinon(Type elementType, IQueryable query, Microsoft.OData.Core.UriParser.Semantic.ApplyAggregateClause transformation, Linq.Expressions.LambdaExpression propertyToAggregateExpression, params string[] parameters) { throw new NotImplementedException(); }