Sha256: 4105bf53fe05c02cc0126a2a13722b90d6949ff9bb6ab34c6124aa579b5c1bbc

Contents?: true

Size: 734 Bytes

Versions: 24

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    #
    # Decorator for trustee
    #
    class TrusteePresenter < SimpleDelegator
      def trustee
        __getobj__
      end

      def public_key_thumbprint
        @public_key_thumbprint ||= format_thumbprint(jwk_thumbprint(JSON.parse(trustee.public_key))) if trustee.public_key.present?
      end

      private

      def format_thumbprint(thumbprint)
        "<pre class='text-small text-muted'>#{thumbprint[0..14]}\n#{thumbprint[15..-16]}\n#{thumbprint[-15..-1]}</pre>".html_safe
      end

      def jwk_thumbprint(key)
        Base64.urlsafe_encode64(Digest::SHA256.digest(key.slice("e", "kty", "n").to_json), padding: false)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
decidim-elections-0.27.9 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.8 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.7 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.6 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.26.10 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.26.9 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.5 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.26.8 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.4 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.3 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.26.7 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.26.5 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.2 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.1 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.26.4 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.0 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.26.3 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.0.rc2 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.27.0.rc1 app/presenters/decidim/elections/trustee_presenter.rb
decidim-elections-0.26.2 app/presenters/decidim/elections/trustee_presenter.rb