diff options
author | Hans Nilsson <hans@erlang.org> | 2020-06-01 17:36:38 +0200 |
---|---|---|
committer | Hans Nilsson <hans@erlang.org> | 2020-06-16 11:42:34 +0200 |
commit | 3a0ff7163a01d26d98b7c4f683d19c9c3204cde2 (patch) | |
tree | 999cb8e87b17fab0b882be74e035349f5fe933f4 /lib/ssh | |
parent | b07393c4f6e2cc303b8d311d066735e2d34d8663 (diff) | |
download | erlang-3a0ff7163a01d26d98b7c4f683d19c9c3204cde2.tar.gz |
ssh: Make version handling more efficient
Raise coverage:
ssh_transport 0.8610 -> 0.8625
ssh_options 0.7167 -> 0.7192
total 0.7277 -> 0.7284
Diffstat (limited to 'lib/ssh')
-rw-r--r-- | lib/ssh/src/ssh_options.erl | 6 | ||||
-rw-r--r-- | lib/ssh/src/ssh_transport.erl | 23 |
2 files changed, 10 insertions, 19 deletions
diff --git a/lib/ssh/src/ssh_options.erl b/lib/ssh/src/ssh_options.erl index 306eb86c23..474d1e5d90 100644 --- a/lib/ssh/src/ssh_options.erl +++ b/lib/ssh/src/ssh_options.erl @@ -670,7 +670,11 @@ default(common) -> }, id_string => - #{default => undefined, % FIXME: see ssh_transport:ssh_vsn/0 + #{default => try {ok, [_|_] = VSN} = application:get_key(ssh, vsn), + "Erlang/" ++ VSN + catch + _:_ -> "" + end, chk => fun(random) -> {true, {random,2,5}}; % 2 - 5 random characters ({random,I1,I2}) -> diff --git a/lib/ssh/src/ssh_transport.erl b/lib/ssh/src/ssh_transport.erl index bd901c99e0..8147f17e05 100644 --- a/lib/ssh/src/ssh_transport.erl +++ b/lib/ssh/src/ssh_transport.erl @@ -255,27 +255,19 @@ versions(server, Options) -> Vsn = ?GET_INTERNAL_OPT(vsn, Options, ?DEFAULT_SERVER_VERSION), {Vsn, format_version(Vsn, software_version(Options))}. +format_version({Major,Minor}, "") -> + lists:concat(["SSH-",Major,".",Minor]); +format_version({Major,Minor}, SoftwareVersion) -> + lists:concat(["SSH-",Major,".",Minor,"-",SoftwareVersion]). + software_version(Options) -> case ?GET_OPT(id_string, Options) of - undefined -> - "Erlang"++ssh_vsn(); {random,Nlo,Nup} -> random_id(Nlo,Nup); ID -> ID end. -ssh_vsn() -> - try {ok,L} = application:get_all_key(ssh), - proplists:get_value(vsn, L, "") - of - "" -> ""; - VSN when is_list(VSN) -> "/" ++ VSN; - _ -> "" - catch - _:_ -> "" - end. - random_id(Nlo, Nup) -> [$a + rand:uniform($z-$a+1) - 1 || _<- lists:duplicate(Nlo + rand:uniform(Nup-Nlo+1) - 1, x)]. @@ -285,17 +277,12 @@ hello_version_msg(Data) -> next_seqnum(SeqNum) -> (SeqNum + 1) band 16#ffffffff. - is_valid_mac(_, _ , #ssh{recv_mac_size = 0}) -> true; is_valid_mac(Mac, Data, #ssh{recv_mac = Algorithm, recv_mac_key = Key, recv_sequence = SeqNum}) -> crypto:equal_const_time(Mac, mac(Algorithm, Key, SeqNum, Data)). -format_version({Major,Minor}, SoftwareVersion) -> - "SSH-" ++ integer_to_list(Major) ++ "." ++ - integer_to_list(Minor) ++ "-" ++ SoftwareVersion. - handle_hello_version(Version) -> try StrVersion = trim_tail(Version), |