public bool Equals(ISafeBytes other) { if (Length != other?.Length) { return(false); } var asSafeBytes = other as SafeBytes; if (asSafeBytes != null) { for (var i = 0; i < Length; i++) { if (!GetAsSafeByte(i).Equals(asSafeBytes.GetAsSafeByte(i))) { return(false); } } } else { for (var i = 0; i < Length; i++) { if (!GetAsSafeByte(i).Equals(other.GetByte(i))) { return(false); } } } return(true); }
/// <summary> /// Clones and appends the each byte from given SafeBytes object to the end. /// </summary> /// <exception cref="ArgumentNullException">Throws if the argument is null</exception> /// <exception cref="ObjectDisposedException">Throws if the SafeBytes instance is disposed</exception> /// <exception cref="ArgumentException">Throws if the argument is empty</exception> public void Append(ISafeBytes safeBytes) { EnsureNotDisposed(); if (safeBytes == null) { throw new ArgumentNullException(nameof(safeBytes)); } if (safeBytes.IsDisposed) { throw new ObjectDisposedException(nameof(safeBytes)); } if (safeBytes.Length == 0) { throw new ArgumentException($"{nameof(safeBytes)} is empty."); } //If it's the known SafeBytes then it reveals nothing in the memory var asSafeBytes = safeBytes as SafeBytes; if (asSafeBytes != null) { for (var i = 0; i < safeBytes.Length; i++) { var safeByte = asSafeBytes.GetAsSafeByte(i); _safeByteCollection.Append(safeByte); } } //If it's not, then reveals each byte in memory. else { for (var i = 0; i < safeBytes.Length; i++) { var safeByte = _safeByteFactory.GetByByte(safeBytes.GetByte(i)); _safeByteCollection.Append(safeByte); } } //Add the arbitrary byte }