<commit_before>require 'openssl'

module Travis::API::V3
  class Models::SslKey < Model
    include Models::Fingerprint

    belongs_to :repository

    serialize :private_key, Travis::Settings::EncryptedColumn.new

    def generate_keys!
      self.public_key = self.private_key = nil
      generate_keys
    end

    def generate_keys
      unless public_key && private_key
        keys = OpenSSL::PKey::RSA.generate(Travis.config.repository.ssl_key.size)
        self.public_key = keys.public_key.to_s
        self.private_key = keys.to_pem
      end
    end

    def fingerprint_source
      public_key
    end

    def encoded_public_key
      key = build_key.public_key
      ['ssh-rsa ', "\0\0\0\assh-rsa#{sized_bytes(key.e)}#{sized_bytes(key.n)}"].pack('a*m').gsub("\n", '')
    end
<commit_msg>Calculate fingerprint of ssl key from private key<commit_after>require 'openssl'

module Travis::API::V3
  class Models::SslKey < Model
    include Models::Fingerprint

    belongs_to :repository

    serialize :private_key, Travis::Settings::EncryptedColumn.new

    def generate_keys!
      self.public_key = self.private_key = nil
      generate_keys
    end

    def generate_keys
      unless public_key && private_key
        keys = OpenSSL::PKey::RSA.generate(Travis.config.repository.ssl_key.size)
        self.public_key = keys.public_key.to_s
        self.private_key = keys.to_pem
      end
    end

    def fingerprint_source
      private_key
    end

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

{'fraction_non_alphanumeric': 0.10955569080949483, 'fraction_numerical': 0.004869141813755326, 'mean_word_length': 3.0492610837438425, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7373046', 'n_tokens_mistral': 563, 'n_tokens_neox': 538, 'n_words': 97}