diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nickserver/hkp/key_info.rb | 49 |
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 |