From ffefe05c5386a5397c069ca5b7ddf88d81cbc0eb Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Mon, 7 Sep 2020 20:00:03 -0700 Subject: [PATCH] Add argument checks --- src/NmeaParser/Gnss/Ntrip/Client.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/NmeaParser/Gnss/Ntrip/Client.cs b/src/NmeaParser/Gnss/Ntrip/Client.cs index 1097c14..e0a19a6 100644 --- a/src/NmeaParser/Gnss/Ntrip/Client.cs +++ b/src/NmeaParser/Gnss/Ntrip/Client.cs @@ -38,7 +38,11 @@ namespace NmeaParser.Gnss.Ntrip /// Port, usually 2101 public Client(string host, int port) { + if (host == null) + throw new ArgumentNullException(nameof(host)); _host = host; + if (port < 1) + throw new ArgumentOutOfRangeException(nameof(port)); _port = port; } @@ -49,9 +53,10 @@ namespace NmeaParser.Gnss.Ntrip /// Port, usually 2101 /// Username /// Password - public Client(string host, int port, string username, string password) : this(host, port) + public Client(string host, int port, string? username, string? password) : this(host, port) { - _auth = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password)); + if (!string.IsNullOrEmpty(username) || !string.IsNullOrEmpty(password)) + _auth = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password)); } ///