dlech.SshAgentLib.Agent.AddKey C# (CSharp) Method

AddKey() public method

public AddKey ( ISshKey key ) : void
key ISshKey
return void
        public void AddKey(ISshKey key)
        {
            if (IsLocked) {
            throw new AgentLockedException();
              }

              /* handle constraints */

              foreach (KeyConstraint constraint in key.Constraints) {
            if (constraint.Type ==
                  KeyConstraintType.SSH_AGENT_CONSTRAIN_CONFIRM &&
                  ConfirmUserPermissionCallback == null) {
              // can't add key with confirm constraint if we don't have
              // confirm callback
              throw new CallbackNullException();
            }
            if (constraint.Type ==
            Agent.KeyConstraintType.SSH_AGENT_CONSTRAIN_LIFETIME) {
              UInt32 lifetime = (UInt32)constraint.Data * 1000;
              Timer timer = new Timer(lifetime);
              ElapsedEventHandler onTimerElapsed = null;
              onTimerElapsed =
            delegate(object aSender, ElapsedEventArgs aEventArgs)
            {
              timer.Elapsed -= onTimerElapsed;
              RemoveKey(key);
            };
              timer.Elapsed += onTimerElapsed;
              timer.Start();
            }
              }

              /* first remove matching key if it exists */
              ISshKey matchingKey = mKeyList.Get(key.Version, key.GetPublicKeyBlob());
              RemoveKey(matchingKey);

              mKeyList.Add(key);
              FireKeyAdded(key);
        }