Sha256: b0de1943d8352f7bab54b16913115d7cc52bc1077734eff9ab3964c95425e0e5

Contents?: true

Size: 914 Bytes

Versions: 13

Compression:

Stored size: 914 Bytes

Contents

require 'openssl'
require 'base64'

module Travis
  module Tools
    module SSLKey
      extend self

      def generate_rsa(size = 2048)
        OpenSSL::PKey::RSA.generate(size)
      end

      def public_rsa_key(string)
        @to_rsa ||= OpenSSL::PKey::RSA.new(string)
      rescue OpenSSL::PKey::RSAError
        public_key = string.gsub('RSA PUBLIC KEY', 'PUBLIC KEY')
        @to_rsa = OpenSSL::PKey::RSA.new(public_key)
      end

      def rsa_ssh(key)
        ['ssh-rsa ', "\0\0\0\assh-rsa#{sized_bytes(key.e)}#{sized_bytes(key.n)}"].pack('a*m').gsub("\n", '')
      end

      def sized_bytes(value)
        bytes = to_byte_array(value.to_i)
        [bytes.size, *bytes].pack('NC*')
      end

      def to_byte_array(num, *significant)
        return significant if num.between?(-1, 0) and significant[0][7] == num[7]
        to_byte_array(*num.divmod(256)) + significant
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
travis-1.6.18.travis.611.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.610.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.609.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.608.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.607.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.606.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.605.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.604.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.596.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.595.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.594.5 lib/travis/tools/ssl_key.rb
travis-1.6.18.travis.592.5 lib/travis/tools/ssl_key.rb
travis-1.6.17 lib/travis/tools/ssl_key.rb