summaryrefslogtreecommitdiff
path: root/lib/nickserver/hkp
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2017-09-23 15:41:56 +0200
committerAzul <azul@riseup.net>2017-09-23 16:53:27 +0200
commit8ac6bb8492c9a3b9ec5d7b5bf2b35907a1f8c332 (patch)
tree08ffafb2c70935892e975704911080b9da84e391 /lib/nickserver/hkp
parentb2543051d0629ab11adae1a64a1aed2105a1b9d9 (diff)
style: avoid endless elsif in KeyInfo#error
using an array of symbols representing the different checks now.
Diffstat (limited to 'lib/nickserver/hkp')
-rw-r--r--lib/nickserver/hkp/key_info.rb49
1 files changed, 27 insertions, 22 deletions
diff --git a/lib/nickserver/hkp/key_info.rb b/lib/nickserver/hkp/key_info.rb
index 568a798..e1a9500 100644
--- a/lib/nickserver/hkp/key_info.rb
+++ b/lib/nickserver/hkp/key_info.rb
@@ -21,17 +21,12 @@ module Nickserver::Hkp
@uids = extract_uids(uid_lines)
end
+ CHECKS = %i[too_short? expired? revoked? disabled? outdated?].freeze
+
def error
- if keylen < 2048
- 'key length is too short.'
- elsif expired?
- 'key expired.'
- elsif revoked?
- 'key revoked.'
- elsif disabled?
- 'key disabled.'
- elsif expirationdate && expirationdate < Time.now
- 'key expired'
+ CHECKS.find do |check|
+ msg = check.to_s.chop.tr('_', ' ')
+ "key is #{msg}." if send(check)
end
end
@@ -69,18 +64,6 @@ module Nickserver::Hkp
algo == '17'
end
- def revoked?
- flags =~ /r/
- end
-
- def disabled?
- flags =~ /d/
- end
-
- def expired?
- flags =~ /e/
- end
-
protected
attr_reader :properties
@@ -93,5 +76,27 @@ module Nickserver::Hkp
CGI.unescape(uid.sub(/.*<(.+)>.*/, '\1'))
end
end
+
+ # CHECKS
+
+ def too_short?
+ keylen < 2048
+ end
+
+ def expired?
+ flags =~ /e/
+ end
+
+ def revoked?
+ flags =~ /r/
+ end
+
+ def disabled?
+ flags =~ /d/
+ end
+
+ def outdated?
+ expirationdate && expirationdate < Time.now
+ end
end
end