From 69d153a12187fa41d8141407919508cb8cf417b2 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sun, 26 Jan 2020 09:49:10 -0800 Subject: [PATCH] Mark fields as readonly but allow for deserializer to set them. This will prevent accidental reassignment of these fields. Without the JsonProperty attribute, we would encounter an issue starting the server when a password was set on the web UI. --- .../HttpServerConnection.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Duplicati/GUI/Duplicati.GUI.TrayIcon/HttpServerConnection.cs b/Duplicati/GUI/Duplicati.GUI.TrayIcon/HttpServerConnection.cs index 574b9bfc5..19fd89ec2 100644 --- a/Duplicati/GUI/Duplicati.GUI.TrayIcon/HttpServerConnection.cs +++ b/Duplicati/GUI/Duplicati.GUI.TrayIcon/HttpServerConnection.cs @@ -6,6 +6,7 @@ using System.Text; using Duplicati.Library.Common.IO; using Duplicati.Server.Serialization; using Duplicati.Server.Serialization.Interface; +using Newtonsoft.Json; namespace Duplicati.GUI.TrayIcon { @@ -226,13 +227,13 @@ namespace Duplicati.GUI.TrayIcon private class SaltAndNonce { - // ReSharper disable once FieldCanBeMadeReadOnly.Local - // This cannot be made readonly as its value is set by a deserializer. - public string Salt = null; - - // ReSharper disable once FieldCanBeMadeReadOnly.Local - // This cannot be made readonly as its value is set by a deserializer. - public string Nonce = null; + // The JsonProperty attribute allows the Serializer.Deserialize method to + // set these readonly fields. + [JsonProperty] + public readonly string Salt = null; + + [JsonProperty] + public readonly string Nonce = null; } private SaltAndNonce GetSaltAndNonce()