diff options
| author | azul <azul@riseup.net> | 2016-06-15 14:22:08 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-15 14:22:08 +0200 | 
| commit | 3c6dc3d7b902b46b82a3d8cd38bd3fa896024beb (patch) | |
| tree | 559b3998465248138b6f24a76b6b3e55e60f3986 /lib/nickserver/hkp/parse_key_info.rb | |
| parent | 5cad637a4a2a3de6b95ff1204fc29174e18b3124 (diff) | |
| parent | 93258bd6fe6247e7af67f423243eba9808e920ee (diff) | |
Merge pull request #3 from azul/refactor/transport-adapters
Refactor em specifics into http adapter
Diffstat (limited to 'lib/nickserver/hkp/parse_key_info.rb')
| -rw-r--r-- | lib/nickserver/hkp/parse_key_info.rb | 26 | 
1 files changed, 17 insertions, 9 deletions
| diff --git a/lib/nickserver/hkp/parse_key_info.rb b/lib/nickserver/hkp/parse_key_info.rb index 8934829..9d59d6b 100644 --- a/lib/nickserver/hkp/parse_key_info.rb +++ b/lib/nickserver/hkp/parse_key_info.rb @@ -1,29 +1,37 @@  # -# Simple parser for HKP KeyInfo responses. +# 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; module HKP +module Nickserver; module 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 -    #  header        -- header of the hkp response +    #  status        -- http status of the hkp response      #  vindex_result -- raw output from a vindex hkp query (machine readable) -    def initialize(header, vindex_result) -      @header = header +    def initialize(status, vindex_result) +      @status = status        @vindex_result = vindex_result      end -    def status(uid) +    def status_for(uid)        if hkp_ok? && keys(uid).empty?          error_status(uid)        else -        header.status +        status +      end +    end + +    def response_for(uid) +      if keys(uid).any? +        keys(uid) +      else +        msg(uid)        end      end @@ -41,7 +49,7 @@ module Nickserver; module HKP      protected -    attr_reader :header +    attr_reader :status      attr_reader :vindex_result      def error_status(uid) @@ -78,7 +86,7 @@ module Nickserver; module HKP      end      def hkp_ok? -      header.status == 200 +      status == 200      end      def error_message(uid, key, err) | 
