Sha256: d1c1208b6f771ead9b67daa009ceb107a0a14ad367d5da8ea3644f4dc8ff673f

Contents?: true

Size: 902 Bytes

Versions: 10

Compression:

Stored size: 902 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

require 'openssl'
require 'fileutils'

module Billy
  # A set of common certificate helper methods.
  module CertificateHelpers

    # Give back the date from now plus given days.
    def days_from_now(days)
      Time.now + (days * 24 * 60 * 60)
    end

    # Give back the date from now minus given days.
    def days_ago(days)
      Time.now - (days * 24 * 60 * 60)
    end

    # Generate a random serial number for a certificate.
    def serial
      rand(1_000_000..100_000_000_000)
    end

    # Create/Overwrite a new file with the given name
    # and ensure the location is safely created. Pass
    # back the resulting path.
    def write_file(name, contents)
      path = File.join(Billy.config.certs_path, "#{Process.pid}-#{name}")
      FileUtils.mkdir_p(File.dirname(path))
      File.write(path, contents)
      path
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
puffing-billy-4.0.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-3.2.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-3.1.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-3.0.4 lib/billy/ssl/certificate_helpers.rb
puffing-billy-3.0.3 lib/billy/ssl/certificate_helpers.rb
puffing-billy-3.0.2 lib/billy/ssl/certificate_helpers.rb
puffing-billy-3.0.1 lib/billy/ssl/certificate_helpers.rb
puffing-billy-3.0.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-2.4.1 lib/billy/ssl/certificate_helpers.rb
puffing-billy-2.4.0 lib/billy/ssl/certificate_helpers.rb