Пример #1
0
        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        private void EnsureCapacity(int capacity)
        {
            // Make sure the requested capacity doesn't exceed SecureString's defined limit
            if (capacity > MaxLength)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.ArgumentOutOfRange_Capacity);
            }

            // If we already have enough space allocated, we're done
            if (_buffer != null && (capacity * sizeof(char)) <= (int)_buffer.ByteLength)
            {
                return;
            }

            // We need more space, so allocate a new buffer, copy all our data into it,
            // and then swap the new for the old.
            ProtectedBuffer newBuffer = ProtectedBuffer.Allocate(capacity * sizeof(char));

            if (_buffer != null)
            {
                using (_buffer.Unprotect())
                    ProtectedBuffer.Copy(_buffer, newBuffer, _buffer.ByteLength);
                newBuffer.Protect();
                _buffer.Dispose();
            }
            _buffer = newBuffer;
        }
Пример #2
0
 public void Dispose()
 {
     _buffer.Protect();
 }