summaryrefslogtreecommitdiff
path: root/lib/nickserver/wkd/url.rb
blob: 965e7ec2a5f11cd1296ee7cca7e5390afab64661 (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
29
30
31
require 'digest/sha1'
require 'zbase32'

module Nickserver
  module Wkd
    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/#{domain}/#{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
end