summaryrefslogtreecommitdiff
path: root/lib/net/ssh/transport/algorithms.rb
diff options
context:
space:
mode:
authorMiklós Fazekas <mfazekas@szemafor.com>2020-04-24 18:17:09 +0200
committerGitHub <noreply@github.com>2020-04-24 18:17:09 +0200
commit9bed3c7f210ac5de54e6b787cce8498f10ce5c79 (patch)
tree828b50dfa472a0f4668e18ee0e8fbe2bddf42d00 /lib/net/ssh/transport/algorithms.rb
parentf6dda96a5fe4741e2957e0ec879d229fca6f3b53 (diff)
parentc457c06394c8e182c9b213fa7a2738c37bd47f7d (diff)
downloadnet-ssh-9bed3c7f210ac5de54e6b787cce8498f10ce5c79.tar.gz
Merge pull request #751 from maxfierke/mf-support_algo_subtraction
Support algorithm subtraction syntax from ssh_config
Diffstat (limited to 'lib/net/ssh/transport/algorithms.rb')
-rw-r--r--lib/net/ssh/transport/algorithms.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/net/ssh/transport/algorithms.rb b/lib/net/ssh/transport/algorithms.rb
index 35d9ec6..c03c92a 100644
--- a/lib/net/ssh/transport/algorithms.rb
+++ b/lib/net/ssh/transport/algorithms.rb
@@ -291,10 +291,24 @@ module Net
list = []
option = Array(option).compact.uniq
- if option.first && option.first.start_with?('+')
+ if option.first && option.first.start_with?('+', '-')
list = supported.dup
- list << option.first[1..-1]
- list.concat(option[1..-1])
+
+ appends = option.select { |opt| opt.start_with?('+') }.map { |opt| opt[1..-1] }
+ deletions = option.select { |opt| opt.start_with?('-') }.map { |opt| opt[1..-1] }
+
+ list.concat(appends)
+
+ deletions.each do |opt|
+ if opt.include?('*')
+ opt_escaped = Regexp.escape(opt)
+ algo_re = /\A#{opt_escaped.gsub('\*', '[A-Za-z\d\-@\.]*')}\z/
+ list.delete_if { |existing_opt| algo_re.match(existing_opt) }
+ else
+ list.delete(opt)
+ end
+ end
+
list.uniq!
else
list = option