Преглед изворни кода

Avoid initializing HostKeyEventArgs when there are no event handlers registered.

Gert Driesen пре 11 година
родитељ
комит
e1c620bfd2
1 измењених фајлова са 6 додато и 5 уклоњено
  1. 6 5
      Renci.SshClient/Renci.SshNet/Security/KeyExchange.cs

+ 6 - 5
Renci.SshClient/Renci.SshNet/Security/KeyExchange.cs

@@ -290,14 +290,15 @@ namespace Renci.SshNet.Security
         /// </returns>
         /// </returns>
         protected bool CanTrustHostKey(KeyHostAlgorithm host)
         protected bool CanTrustHostKey(KeyHostAlgorithm host)
         {
         {
-            var args = new HostKeyEventArgs(host);
-
-            if (this.HostKeyReceived != null)
+            var handlers = HostKeyReceived;
+            if (handlers != null)
             {
             {
-                this.HostKeyReceived(this, args);
+                var args = new HostKeyEventArgs(host);
+                handlers(this, args);
+                return args.CanTrust;
             }
             }
 
 
-            return args.CanTrust;
+            return true;
         }
         }
 
 
         /// <summary>
         /// <summary>