From 40916407517f4bdb75a295caf29e02d4f403349b Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 23 Sep 2017 11:07:32 +0200 Subject: style: rubocop mostly auto-correct --- lib/nickserver/hkp/parse_key_info.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'lib/nickserver/hkp/parse_key_info.rb') diff --git a/lib/nickserver/hkp/parse_key_info.rb b/lib/nickserver/hkp/parse_key_info.rb index 2f928a0..09dc69e 100644 --- a/lib/nickserver/hkp/parse_key_info.rb +++ b/lib/nickserver/hkp/parse_key_info.rb @@ -5,9 +5,8 @@ # Parsing a response with 12 keys and validating them takes 2ms. # So no need for memoization and making things more complex. # -module Nickserver; module Hkp +module Nickserver::Hkp class ParseKeyInfo - # for this regexp to work, the source text must end in a trailing "\n", # which the output of sks does. MATCH_PUB_KEY = /(^pub:.+?\n(^uid:.+?\n)+)/m @@ -47,7 +46,7 @@ module Nickserver; module Hkp if errors(uid).any? error_messages(uid).join "\n" else - "Could not fetch keyinfo." + 'Could not fetch keyinfo.' end end @@ -63,7 +62,7 @@ module Nickserver; module Hkp end def errors(uid) - key_infos(uid).map{|key| error_for_key(key) }.compact + key_infos(uid).map { |key| error_for_key(key) }.compact end def error_messages(uid) @@ -97,16 +96,16 @@ module Nickserver; module Hkp def error_for_key(key) if key.keylen < 2048 - "key length is too short." + 'key length is too short.' elsif key.expired? - "key expired." + 'key expired.' elsif key.revoked? - "key revoked." + 'key revoked.' elsif key.disabled? - "key disabled." + 'key disabled.' elsif key.expirationdate && key.expirationdate < Time.now - "key expired" + 'key expired' end end end -end; end +end -- cgit v1.2.3 From f40ef14010af08c49810c0a6a2349072948170e6 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 23 Sep 2017 13:43:29 +0200 Subject: style: more rubocop fixes --- lib/nickserver/hkp/parse_key_info.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/nickserver/hkp/parse_key_info.rb') diff --git a/lib/nickserver/hkp/parse_key_info.rb b/lib/nickserver/hkp/parse_key_info.rb index 09dc69e..c23751b 100644 --- a/lib/nickserver/hkp/parse_key_info.rb +++ b/lib/nickserver/hkp/parse_key_info.rb @@ -1,11 +1,11 @@ -# -# Simple parser for Hkp KeyInfo responses. -# -# Focus is on simple here. Trying to avoid state and sideeffects. -# Parsing a response with 12 keys and validating them takes 2ms. -# So no need for memoization and making things more complex. -# module Nickserver::Hkp + # + # Simple parser for Hkp KeyInfo responses. + # + # Focus is on simple here. Trying to avoid state and sideeffects. + # Parsing a response with 12 keys and validating them takes 2ms. + # So no need for memoization and making things more complex. + # class ParseKeyInfo # for this regexp to work, the source text must end in a trailing "\n", # which the output of sks does. -- cgit v1.2.3 From b2543051d0629ab11adae1a64a1aed2105a1b9d9 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 23 Sep 2017 15:10:11 +0200 Subject: refactor: move error detection into key_info Still needs something better than all these elsifs though --- lib/nickserver/hkp/parse_key_info.rb | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'lib/nickserver/hkp/parse_key_info.rb') diff --git a/lib/nickserver/hkp/parse_key_info.rb b/lib/nickserver/hkp/parse_key_info.rb index c23751b..a6f170c 100644 --- a/lib/nickserver/hkp/parse_key_info.rb +++ b/lib/nickserver/hkp/parse_key_info.rb @@ -39,7 +39,7 @@ module Nickserver::Hkp protected def keys(uid) - key_infos(uid).reject { |key| error_for_key(key) } + key_infos(uid).reject(&:error) end def msg(uid) @@ -62,13 +62,12 @@ module Nickserver::Hkp end def errors(uid) - key_infos(uid).map { |key| error_for_key(key) }.compact + key_infos(uid).map(&:error).compact end def error_messages(uid) key_infos(uid).map do |key| - err = error_for_key(key) - error_message(uid, key, err) + error_message(uid, key) end.compact end @@ -90,22 +89,8 @@ module Nickserver::Hkp status == 200 end - def error_message(uid, key, err) - "Ignoring key #{key.keyid} for #{uid}: #{err}" if err - end - - def error_for_key(key) - if key.keylen < 2048 - 'key length is too short.' - elsif key.expired? - 'key expired.' - elsif key.revoked? - 'key revoked.' - elsif key.disabled? - 'key disabled.' - elsif key.expirationdate && key.expirationdate < Time.now - 'key expired' - end + def error_message(uid, key) + "Ignoring key #{key.keyid} for #{uid}: #{key.error}" if key.error end end end -- cgit v1.2.3