static async Task <string> RevealAsync(ISafeString str)
            {
                var strBuilder = new StringBuilder(str.Length);

                for (var i = 0; i < str.Length; i++)
                {
                    strBuilder.Append(await str.RevealDecryptedCharAsync(i));
                }
                return(strBuilder.ToString());
            }
Beispiel #2
0
 /// <exception cref="ArgumentNullException">
 ///     <paramref name="safeString" /> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ObjectDisposedException">
 ///     Throws if the SafeString instance is disposed.
 /// </exception>
 public void Append(ISafeString safeString)
 {
     if (safeString == null)
     {
         throw new ArgumentNullException(nameof(safeString));
     }
     EnsureNotDisposed();
     for (var i = 0; i < safeString.Length; i++)
     {
         Append(safeString.GetAsSafeBytes(i).DeepClone());
     }
 }
Beispiel #3
0
        public void EqualsAsyncISafeString_NullArgument_Throws()
        {
            // Arrange
            using var sut = GetSut();
            ISafeString nullInstance = null;

            // Act
            Task Equals() => sut.EqualsAsync(nullInstance);

            // Assert
            Assert.ThrowsAsync <ArgumentNullException>(Equals);
        }
Beispiel #4
0
 /// <inheritdoc />
 /// <inheritdoc cref="DisposableBase.ThrowIfDisposed"/>
 /// <exception cref="ArgumentNullException"><paramref name="safeString" /> is <see langword="null" />. </exception>
 public async Task AppendAsync(ISafeString safeString)
 {
     if (safeString == null)
     {
         throw new ArgumentNullException(nameof(safeString));
     }
     ThrowIfDisposed();
     for (var i = 0; i < safeString.Length; i++)
     {
         var @byte = await safeString.GetAsSafeBytes(i).DeepCloneAsync().ConfigureAwait(false);
         await AppendAsync(@byte).ConfigureAwait(false);
     }
 }
Beispiel #5
0
 public bool Equals(ISafeString other)
 {
     if (other?.Length != Length)
     {
         return(false);
     }
     for (var i = 0; i < Length; i++)
     {
         if (!GetAsSafeBytes(i).Equals(other.GetAsSafeBytes(i)))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #6
0
 public static bool IsNullOrEmpty(ISafeString safeString)
 => (safeString == null) || safeString.IsDisposed || safeString.IsEmpty;
Beispiel #7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="SafeStringToStringMarshaler" /> class using a
 ///     <see cref="ISafeString" />. Plain data of the <paramref name="safeString" /> will be available in
 ///     <see cref="String" /> property until this instance is disposed.
 /// </summary>
 /// <param name="safeString">The safe string to decrypt.</param>
 public SafeStringToStringMarshaler(ISafeString safeString)
 {
     SafeString = safeString;
 }
Beispiel #8
0
 /// <summary>
 ///     For easier syntax to append and return the appended instance.
 /// </summary>
 /// <example>
 ///     <code>new SafeBytes().AppendAndReturnDeepClone(5).AppendAndReturnDeepClone(10);</code>
 /// </example>
 /// <exception cref="ObjectDisposedException">Throws if the SafeBytes instance is disposed</exception>
 public static ISafeString AppendAndReturnDeepClone(this ISafeString safeString, char c)
 {
     safeString.Append(c);
     return(safeString.DeepClone());
 }
 public SqlQueryPreparator(ISafeString safeString)
 {
     _safeString = safeString;
 }