Remove some unused constructors
MODIFY
WalletWasabi/Tor/Socks5/Models/Bases/ByteArraySerializableBase.cs
WalletWasabi/Tor/Socks5/Models/Bases/ByteArraySerializableBase.cs
@@ -7,16 +7,6 @@ namespace WalletWasabi.Tor.Socks5.Models.Bases
{
public abstract class ByteArraySerializableBase : IByteArraySerializable, IEquatable<ByteArraySerializableBase>, IEquatable<byte[]>
{
- #region ConstructorsAndInitializers
-
- protected ByteArraySerializableBase()
- {
- }
-
- #endregion ConstructorsAndInitializers
-
- #region Serialization
-
public abstract byte[] ToBytes();
public abstract void FromBytes(byte[] bytes);
@@ -50,10 +40,6 @@ namespace WalletWasabi.Tor.Socks5.Models.Bases
return ToHex(xhhSyntax: true);
}
- #endregion Serialization
-
- #region EqualityAndComparison
-
public static bool operator ==(ByteArraySerializableBase x, ByteArraySerializableBase y) => ByteHelpers.CompareFastUnsafe(x?.ToBytes(), y?.ToBytes());
public static bool operator !=(ByteArraySerializableBase x, ByteArraySerializableBase y) => !(x == y);
@@ -92,7 +78,5 @@ namespace WalletWasabi.Tor.Socks5.Models.Bases
}
public bool Equals(byte[] other) => ByteHelpers.CompareFastUnsafe(ToBytes(), other);
-
- #endregion EqualityAndComparison
}
}

MODIFY
WalletWasabi/Tor/Socks5/Models/Fields/ByteArrayFields/PasswdField.cs
WalletWasabi/Tor/Socks5/Models/Fields/ByteArrayFields/PasswdField.cs
@@ -6,34 +6,18 @@ namespace WalletWasabi.Tor.Socks5.Models.Fields.ByteArrayFields
{
public class PasswdField : ByteArraySerializableBase
{
- #region Constructors
-
- public PasswdField()
- {
- }
-
public PasswdField(string passwd)
{
Guard.NotNullOrEmpty(nameof(passwd), passwd);
Bytes = Encoding.UTF8.GetBytes(passwd);
}
- #endregion Constructors
-
- #region PropertiesAndMembers
-
private byte[] Bytes { get; set; }
public string Passwd => Encoding.UTF8.GetString(Bytes); // Tor accepts UTF8 encoded passwd
- #endregion PropertiesAndMembers
-
- #region Serialization
-
public override void FromBytes(byte[] bytes) => Bytes = Guard.NotNullOrEmpty(nameof(bytes), bytes);
public override byte[] ToBytes() => Bytes;
-
- #endregion Serialization
}
}

MODIFY
WalletWasabi/Tor/Socks5/Models/Fields/OctetFields/PLenField.cs
WalletWasabi/Tor/Socks5/Models/Fields/OctetFields/PLenField.cs
@@ -6,34 +6,17 @@ namespace WalletWasabi.Tor.Socks5.Models.Fields.OctetFields
{
public class PLenField : OctetSerializableBase
{
- #region Constructors
-
public PLenField()
{
}
- public PLenField(int value)
- {
- ByteValue = (byte)Guard.InRangeAndNotNull(nameof(value), value, 0, 255);
- }
-
- #endregion Constructors
-
- #region PropertiesAndMembers
-
public int Value => ByteValue;
- #endregion PropertiesAndMembers
-
- #region Serialization
-
public void FromPasswdField(PasswdField passwd)
{
Guard.NotNull(nameof(passwd), passwd);
ByteValue = (byte)passwd.ToBytes().Length;
}
-
- #endregion Serialization
}
}

MODIFY
WalletWasabi/Tor/Socks5/Models/Fields/OctetFields/ULenField.cs
WalletWasabi/Tor/Socks5/Models/Fields/OctetFields/ULenField.cs
-using WalletWasabi.Helpers;
using WalletWasabi.Tor.Socks5.Models.Bases;
using WalletWasabi.Tor.Socks5.Models.Fields.ByteArrayFields;
@@ -6,32 +5,15 @@ namespace WalletWasabi.Tor.Socks5.Models.Fields.OctetFields
{
public class ULenField : OctetSerializableBase
{
- #region Constructors
-
public ULenField()
{
}
- public ULenField(int value)
- {
- ByteValue = (byte)Guard.InRangeAndNotNull(nameof(value), value, 0, 255);
- }
-
- #endregion Constructors
-
- #region PropertiesAndMembers
-
public int Value => ByteValue;
- #endregion PropertiesAndMembers
-
- #region Serialization
-
public void FromUNameField(UNameField uName)
{
ByteValue = (byte)uName.ToBytes().Length;
}
-
- #endregion Serialization
}
}

MODIFY
WalletWasabi/Tor/Socks5/Models/Messages/TorSocks5Response.cs
WalletWasabi/Tor/Socks5/Models/Messages/TorSocks5Response.cs
@@ -8,26 +8,10 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
{
public class TorSocks5Response : ByteArraySerializableBase
{
- #region Constructors
-
public TorSocks5Response()
{
}
- public TorSocks5Response(RepField rep, AddrField bndAddr, PortField bndPort)
- {
- Rep = Guard.NotNull(nameof(rep), rep);
- BndAddr = Guard.NotNull(nameof(bndAddr), bndAddr);
- BndPort = Guard.NotNull(nameof(bndPort), bndPort);
- Ver = VerField.Socks5;
- Rsv = RsvField.X00;
- Atyp = bndAddr.Atyp;
- }
-
- #endregion Constructors
-
- #region PropertiesAndMembers
-
public VerField Ver { get; set; }
public RepField Rep { get; set; }
@@ -40,10 +24,6 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
public PortField BndPort { get; set; }
- #endregion PropertiesAndMembers
-
- #region Serialization
-
public override void FromBytes(byte[] bytes)
{
Guard.NotNullOrEmpty(nameof(bytes), bytes);
@@ -68,7 +48,5 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
}
public override byte[] ToBytes() => ByteHelpers.Combine(new byte[] { Ver.ToByte(), Rep.ToByte(), Rsv.ToByte(), Atyp.ToByte() }, BndAddr.ToBytes(), BndPort.ToBytes());
-
- #endregion Serialization
}
}

MODIFY
WalletWasabi/Tor/Socks5/Models/Messages/UsernamePasswordRequest.cs
WalletWasabi/Tor/Socks5/Models/Messages/UsernamePasswordRequest.cs
@@ -8,12 +8,6 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
{
public class UsernamePasswordRequest : ByteArraySerializableBase
{
- #region Constructors
-
- public UsernamePasswordRequest()
- {
- }
-
public UsernamePasswordRequest(UNameField uName, PasswdField passwd)
{
Ver = AuthVerField.Version1;
@@ -28,10 +22,6 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
ULen = uLen;
}
- #endregion Constructors
-
- #region PropertiesAndMembers
-
public AuthVerField Ver { get; set; }
public ULenField ULen { get; set; }
@@ -42,10 +32,6 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
public PasswdField Passwd { get; set; }
- #endregion PropertiesAndMembers
-
- #region Serialization
-
public override void FromBytes(byte[] bytes)
{
Guard.NotNullOrEmpty(nameof(bytes), bytes);
@@ -71,7 +57,5 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
}
public override byte[] ToBytes() => ByteHelpers.Combine(new byte[] { Ver.ToByte(), ULen.ToByte() }, UName.ToBytes(), new byte[] { PLen.ToByte() }, Passwd.ToBytes());
-
- #endregion Serialization
}
}

MODIFY
WalletWasabi/Tor/Socks5/Models/Messages/UsernamePasswordResponse.cs
WalletWasabi/Tor/Socks5/Models/Messages/UsernamePasswordResponse.cs
@@ -6,30 +6,14 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
{
public class UsernamePasswordResponse : ByteArraySerializableBase
{
- #region Constructors
-
public UsernamePasswordResponse()
{
}
- public UsernamePasswordResponse(AuthStatusField status)
- {
- Status = Guard.NotNull(nameof(status), status);
- Ver = AuthVerField.Version1;
- }
-
- #endregion Constructors
-
- #region PropertiesAndMembers
-
public AuthVerField Ver { get; set; }
public AuthStatusField Status { get; set; }
- #endregion PropertiesAndMembers
-
- #region Serialization
-
public override void FromBytes(byte[] bytes)
{
Guard.NotNullOrEmpty(nameof(bytes), bytes);
@@ -47,7 +31,5 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
Ver.ToByte(),
Status.ToByte()
};
-
- #endregion Serialization
}
}

Remove some unused constructors