<commit_before>package security

import (
	"crypto/rand"
	"crypto/rsa"
	"gost/util/jsonutil"
	"log"

	"github.com/square/go-jose"
)

var privateKey = new(rsa.PrivateKey)
var encrypter jose.Encrypter

// Encrypt encrypts a byte slice using RSA with a private key
func Encrypt(data []byte) ([]byte, error) {
	object, err := encrypter.Encrypt(data)
	if err != nil {
		return nil, err
	}

	encryptedString := object.FullSerialize()
	return []byte(encryptedString), nil
}

// Decrypt decrypts a byte slice using RSA with a private key
func Decrypt(data []byte) ([]byte, error) {
	object, err := jose.ParseEncrypted(string(data))
	if err != nil {
		return nil, err
	}

	decryptedData, err := object.Decrypt(privateKey)
	if err != nil {
		return nil, err
	}

	return decryptedData, nil
}

// GeneratePrivateKey generates and prints in the terminal/log the byte array
// containing a private RSA key serialized as a JSON value
func GeneratePrivateKey(printInLog bool) []byte {
	priv, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		panic(err)
	}

	data, err := jsonutil.SerializeJSON(priv)
	if err != nil {
		panic(err)
	}

	if printInLog {
		log.Println(data)
	}

	return data
}

// InitCipherModule initializes the components used for server-side encryption
func InitCipherModule() {
	var err error

	// Generate the private key
	privateKey, err = rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		panic(err)
	}

	// Initialize the encryption mechanism using the new private key
	encrypter, err = jose.NewEncrypter(jose.RSA_OAEP, jose.A128GCM, &privateKey.PublicKey)
	if err != nil {
		panic(err)
	}
}
<commit_msg>Removed unncessary code from the cipher module<commit_after>package security

import (
	"crypto/rand"
	"crypto/rsa"

	"github.com/square/go-jose"
)

var privateKey = new(rsa.PrivateKey)
var encrypter jose.Encrypter

// Encrypt encrypts a byte slice using RSA with a private key
func Encrypt(data []byte) ([]byte, error) {
	object, err := encrypter.Encrypt(data)
	if err != nil {
		return nil, err
	}

	encryptedString := object.FullSerialize()
	return []byte(encryptedString), nil
}

// Decrypt decrypts a byte slice using RSA with a private key
func Decrypt(data []byte) ([]byte, error) {
	object, err := jose.ParseEncrypted(string(data))
	if err != nil {
		return nil, err
	}

	decryptedData, err := object.Decrypt(privateKey)
	if err != nil {
		return nil, err
	}

	return decryptedData, nil
}

// InitCipherModule initializes the components used for server-side encryption
func InitCipherModule() {
	var err error

	// Generate the private key
	privateKey, err = rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		panic(err)
	}

	// Initialize the encryption mechanism using the new private key
	encrypter, err = jose.NewEncrypter(jose.RSA_OAEP, jose.A128GCM, &privateKey.PublicKey)
	if err != nil {
		panic(err)
	}
}

{'fraction_non_alphanumeric': 0.11157894736842106, 'fraction_numerical': 0.00631578947368421, 'mean_word_length': 4.081996434937611, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5749129', 'n_tokens_mistral': 1039, 'n_tokens_neox': 990, 'n_words': 296}