Amazon.Util.CryptoUtilFactory.CryptoUtil.ThreadSafeCreateKeyedHashedAlgorithm C# (CSharp) Method

ThreadSafeCreateKeyedHashedAlgorithm() private method

The iOS il2cpp implementation of System.Security.Cryptography.RandomNumberGenerator, which is called by the initialization of KeyedHashAlgorithm.Create for a given algorithm name, is not threadsafe. We keep track of which algorithms have been initialized, and retain a lock if this is the first time we create a particular algorithm.
private ThreadSafeCreateKeyedHashedAlgorithm ( SigningAlgorithm algorithmName ) : KeyedHashAlgorithm
algorithmName SigningAlgorithm
return KeyedHashAlgorithm
            private KeyedHashAlgorithm ThreadSafeCreateKeyedHashedAlgorithm(SigningAlgorithm algorithmName)
            {
                string algorithmNameUpper = algorithmName.ToString().ToUpper(CultureInfo.InvariantCulture);
                KeyedHashAlgorithm algorithm = null;
                bool firstCreation = true;
                lock (_keyedHashAlgorithmCreationLock)
                {
                    firstCreation = !_initializedAlgorithmNames.Contains(algorithmNameUpper);

                    if (firstCreation)
                    {
                        algorithm = KeyedHashAlgorithm.Create(algorithmNameUpper);
                        _initializedAlgorithmNames.Add(algorithmNameUpper);
                    }
                }
                if (!firstCreation)
                {
                    algorithm = KeyedHashAlgorithm.Create(algorithmNameUpper);
                }
                return algorithm;
            }