Welcome to mirror list, hosted at ThFree Co, Russian Federation.

certificate.rb « smime « email « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 59d7b0c3c5b1df5afe2030a8d7b724d5d3b4241a (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
32
33
34
# frozen_string_literal: true

module Gitlab
  module Email
    module Smime
      class Certificate
        attr_reader :key, :cert

        def key_string
          @key.to_s
        end

        def cert_string
          @cert.to_pem
        end

        def self.from_strings(key_string, cert_string)
          key = OpenSSL::PKey::RSA.new(key_string)
          cert = OpenSSL::X509::Certificate.new(cert_string)
          new(key, cert)
        end

        def self.from_files(key_path, cert_path)
          from_strings(File.read(key_path), File.read(cert_path))
        end

        def initialize(key, cert)
          @key = key
          @cert = cert
        end
      end
    end
  end
end