require 'travis/support/encrypted_column'
require 'travis/support/secure_config'

class SslKey < ActiveRecord::Base
  serialize :private_key, Travis::EncryptedColumn.new

  def encode(string)
    Base64.encode64(encrypt(string)).strip
  end

  def encrypt(string)
    key.public_encrypt(string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
  end

  def decrypt(string)
    key.private_decrypt(string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
  rescue OpenSSL::PKey::RSAError
    key.private_decrypt(string)
  end

  private

    def key
      @key ||= OpenSSL::PKey::RSA.new(private_key)
    end
end

require 'travis/support/encrypted_column'
require 'travis/support/secure_config'

class SslKey < ActiveRecord::Base
  serialize :private_key, Travis::EncryptedColumn.new

  def encode(string)
    Base64.encode64(encrypt(string)).strip
  end

  def encrypt(string)
    key.public_encrypt(string)
  end

  def decrypt(string)
    key.private_decrypt(string)
  end

  private

    def key
      @key ||= OpenSSL::PKey::RSA.new(private_key)
    end
end

Revert "Use OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING when encrypting"
Revert "Use OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING when encrypting"

This reverts commit f4db705c10e9cbea4d344ecb11374baa3071a8be.
