<commit_before>require 'base64'
require 'json'
require 'net/http'
require 'optparse'
require 'openssl'
require 'ostruct'
require 'rbnacl'
require 'securerandom'
require 'uri'

class Client
    @@OIDPrivate = "1.3.6.1.4.1.27266.11.17.2"
    @@OIDPublic  = "1.3.6.1.4.1.27266.11.17.1"
    @@PEMPrivate = "SECRETS PRIVATE KEY"
    @@PEMPublic  = "SECRETS PUBLIC KEY"

    attr_accessor :key, :keyFile, :baseURL, :caFile, :publicKey, :privateKey

    def initialize(keyFile, baseURL, caFile=nil)
        @keyFile = keyFile
        @baseURL = baseURL
        @caFile = caFile

        # Load and parse private key
        @key = Client.loadKeyFile(@@PEMPrivate, @keyFile)
        if @key.value[0].value != @@OIDPrivate
            raise Exception("Key file %s does not contain a SECRETS private key" % keyFile)
        end
        @publicKey = @key.value[1].value.force_encoding('binary')
        @privateKey = @key.value[2].value.force_encoding('binary')

        # Cleanup baseURL to have no trailing slash
        @baseURL = @baseURL.gsub(/\/+$/, '')
    end

    def self.loadKeyFile(type, file)
        keyData = File.read(file)
        derData = self.parsePEM(type, keyData)
        return OpenSSL::ASN1.decode(derData)
    end<commit_msg>secrets-client: reorder Ruby imports<commit_after>require 'base64'
require 'json'
require 'net/http'
require 'optparse'
require 'openssl'
require 'ostruct'
require 'securerandom'
require 'uri'
require 'rbnacl'

class Client
    @@OIDPrivate = "1.3.6.1.4.1.27266.11.17.2"
    @@OIDPublic  = "1.3.6.1.4.1.27266.11.17.1"
    @@PEMPrivate = "SECRETS PRIVATE KEY"
    @@PEMPublic  = "SECRETS PUBLIC KEY"

    attr_accessor :key, :keyFile, :baseURL, :caFile, :publicKey, :privateKey

    def initialize(keyFile, baseURL, caFile=nil)
        @keyFile = keyFile
        @baseURL = baseURL
        @caFile = caFile

        # Load and parse private key
        @key = Client.loadKeyFile(@@PEMPrivate, @keyFile)
        if @key.value[0].value != @@OIDPrivate
            raise Exception("Key file %s does not contain a SECRETS private key" % keyFile)
        end
        @publicKey = @key.value[1].value.force_encoding('binary')
        @privateKey = @key.value[2].value.force_encoding('binary')

        # Cleanup baseURL to have no trailing slash
        @baseURL = @baseURL.gsub(/\/+$/, '')
    end

    def self.loadKeyFile(type, file)
        keyData = File.read(file)
        derData = self.parsePEM(type, keyData)
        return OpenSSL::ASN1.decode(derData)
    end
{'fraction_non_alphanumeric': 0.13264083100279664, 'fraction_numerical': 0.030363563723531762, 'mean_word_length': 2.882170542635659, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, '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': '205741', 'n_tokens_mistral': 916, 'n_tokens_neox': 852, 'n_words': 198}