예제 #1
0
        private char TransformSafeBytesToChar(ISafeBytes safeBytes, Encoding encoding)
        {
            var byteBuffer = safeBytes.ToByteArray();

            try
            {
                return(_textService.GetChars(byteBuffer, InnerEncoding).First());
            }
            finally
            {
                Array.Clear(byteBuffer, 0, byteBuffer.Length);
            }
        }
예제 #2
0
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="character" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     Throws if the SafeString instance is disposed.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Throws if <paramref name="character" /> is less than zero or higher than the length.
        /// </exception>
        public void Insert(int position, ISafeBytes character, Encoding encoding = Encoding.Utf16LittleEndian)
        {
            EnsureNotDisposed();
            if ((position < 0) || (position > Length))
            {
                throw new ArgumentOutOfRangeException(nameof(position));
            }
            if (SafeBytes.IsNullOrEmpty(character))
            {
                throw new ArgumentNullException(nameof(character));
            }
            if (encoding == InnerEncoding)
            {
                _charBytesList.Insert(position, character);
                return;
            }
            //Convert encoding
            var buffer = character.ToByteArray();

            try
            {
                buffer = _textService.Convert(encoding, InnerEncoding, buffer);
                var safeBytes = _safeBytesFactory.Create();
                for (var i = 0; i < buffer.Length; i++)
                {
                    //Append
                    safeBytes.Append(buffer[i]);
                    buffer[i] = 0x0;
                }
                _charBytesList.Insert(position, safeBytes);
            }
            finally
            {
                Array.Clear(buffer, 0, buffer.Length);
            }
        }
예제 #3
0
 public bool Equals(ISafeBytes other)
 {
     return(other != null &&
            _bytes.ToArray().SequenceEqual(other.ToByteArray()));
 }
예제 #4
0
 public void Append(ISafeBytes safeBytes)
 {
     _bytes.AddRange(safeBytes.ToByteArray());
 }