summaryrefslogtreecommitdiff
path: root/lib/nickserver/wkd/url.rb
blob: 0ccff38535da748b5630fd8bba1db76877e365a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'digest/sha1'
require 'zbase32'

module Nickserver::Wkd
  # The url to lookup the given email address in the web key directory.
  class Url
    def initialize(email)
      @domain = email.domain.downcase
      @local_part = email.local_part.downcase
    end

    def to_s
      "https://#{domain}/.well-known/openpgpkey/hu/#{encoded_digest}"
    end

    protected

    attr_reader :domain, :local_part

    def encoded_digest
      ZBase32.encode32(digest.to_i(16).to_s(2))
    end

    def digest
      Digest::SHA1.hexdigest local_part
    end
  end
end