Exemplo n.º 1
0
            private uint GetNextFreeIndex()
            {
                uint idx = 0;

                if (m_values.Count > 0)
                {
                    idx = (uint)m_values[m_values.Count - 1] + 1;

                    // overflow - collapse indexes
                    if (idx == 0)
                    {
                        for (int i = 0; i < m_values.Count; i++)
                        {
                            // if the current index matches the lookup value then we are already in the correct position
                            if (idx == (uint)m_values[i])
                            {
                                idx++;
                            }
                            else
                            {
                                // collapse cert indexes
                                ExtendedWeakReference ewr = ExtendedWeakReference.Recover(typeof(_CertStore_), (uint)m_values[i]);

                                if (ewr != null)
                                {
                                    X509Certificate cert = ewr.Target as X509Certificate;
                                    ewr.Target = null;

                                    ewr = new ExtendedWeakReference(cert, typeof(_CertStore_), idx, ExtendedWeakReference.c_SurvivePowerdown);
                                    ewr.Priority = (int)ExtendedWeakReference.PriorityLevel.Critical;
                                    ewr.Target = cert;
                                    ewr.PushBackIntoRecoverList();

                                    m_values[i] = (uint)idx;

                                    // increment active index count only if we have a valid EWR certificate
                                    idx++;
                                }
                            }
                        }
                    }
                }

                return idx;
            }