Pass via constructor to AtypField
MODIFY
WalletWasabi/Tor/Socks5/Models/Fields/ByteArrayFields/AddrField.cs
WalletWasabi/Tor/Socks5/Models/Fields/ByteArrayFields/AddrField.cs
@@ -20,8 +20,7 @@ namespace WalletWasabi.Tor.Socks5.Models.Fields.ByteArrayFields
{
dstAddr = Guard.NotNullOrEmptyOrWhitespace(nameof(dstAddr), dstAddr, true);
- var atyp = new AtypField();
- atyp.FromDstAddr(dstAddr);
+ var atyp = new AtypField(dstAddr);
Atyp = atyp;

MODIFY
WalletWasabi/Tor/Socks5/Models/Fields/OctetFields/AtypField.cs
WalletWasabi/Tor/Socks5/Models/Fields/OctetFields/AtypField.cs
@@ -7,44 +7,12 @@ namespace WalletWasabi.Tor.Socks5.Models.Fields.OctetFields
{
public class AtypField : OctetSerializableBase
{
- #region Constructors
-
- public AtypField()
- {
- }
-
- #endregion Constructors
-
- #region Statics
-
- // https://gitweb.torproject.org/torspec.git/tree/socks-extensions.txt
- // IPv6 is not supported in CONNECT commands.
-
- public static AtypField IPv4
- {
- get
- {
- var atyp = new AtypField();
- atyp.FromHex("01");
- return atyp;
- }
- }
-
- public static AtypField DomainName
+ public AtypField(byte value)
{
- get
- {
- var atyp = new AtypField();
- atyp.FromHex("03");
- return atyp;
- }
+ ByteValue = value;
}
- #endregion Statics
-
- #region Serialization
-
- public void FromDstAddr(string dstAddr)
+ public AtypField(string dstAddr)
{
dstAddr = Guard.NotNullOrEmptyOrWhitespace(nameof(dstAddr), dstAddr, true);
@@ -60,6 +28,11 @@ namespace WalletWasabi.Tor.Socks5.Models.Fields.OctetFields
}
}
- #endregion Serialization
+ // https://gitweb.torproject.org/torspec.git/tree/socks-extensions.txt
+ // IPv6 is not supported in CONNECT commands.
+
+ public static readonly AtypField IPv4 = new AtypField(0x01);
+
+ public static AtypField DomainName = new AtypField(0x03);
}
}

MODIFY
WalletWasabi/Tor/Socks5/Models/Messages/TorSocks5Request.cs
WalletWasabi/Tor/Socks5/Models/Messages/TorSocks5Request.cs
@@ -49,8 +49,7 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
Rsv = new RsvField();
Rsv.FromByte(bytes[2]);
- Atyp = new AtypField();
- Atyp.FromByte(bytes[3]);
+ Atyp = new AtypField(bytes[3]);
DstAddr = new AddrField();
DstAddr.FromBytes(bytes[4..^2]);

MODIFY
WalletWasabi/Tor/Socks5/Models/Messages/TorSocks5Response.cs
WalletWasabi/Tor/Socks5/Models/Messages/TorSocks5Response.cs
@@ -37,8 +37,7 @@ namespace WalletWasabi.Tor.Socks5.Models.Messages
Rsv = new RsvField();
Rsv.FromByte(bytes[2]);
- Atyp = new AtypField();
- Atyp.FromByte(bytes[3]);
+ Atyp = new AtypField(bytes[3]);
BndAddr = new AddrField();
BndAddr.FromBytes(bytes[4..^2]);

Pass via constructor to AtypField