Sha256: 1308c9547593e42c43dc4e2215b9b69f5c7e40533ab46522d6490739cd860c37

Contents?: true

Size: 882 Bytes

Versions: 14

Compression:

Stored size: 882 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, name)
      FileUtils.mkdir_p(File.dirname(path))
      File.write(path, contents)
      path
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
puffing-billy-2.3.1 lib/billy/ssl/certificate_helpers.rb
puffing-billy-2.3.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-2.2.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-2.1.1 lib/billy/ssl/certificate_helpers.rb
puffing-billy-2.1.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-2.0.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-1.1.3 lib/billy/ssl/certificate_helpers.rb
puffing-billy-1.1.2 lib/billy/ssl/certificate_helpers.rb
puffing-billy-1.1.1 lib/billy/ssl/certificate_helpers.rb
puffing-billy-1.1.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-1.0.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-0.12.0 lib/billy/ssl/certificate_helpers.rb
puffing-billy-0.11.1 lib/billy/ssl/certificate_helpers.rb
puffing-billy-0.11.0 lib/billy/ssl/certificate_helpers.rb