<commit_before>package pusher

import (
	"crypto/hmac"
	"crypto/md5"
	"crypto/rand"
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"errors"
	"fmt"
	"io"
	"strings"

	"golang.org/x/crypto/nacl/secretbox"
)

func hmacSignature(toSign, secret string) string {
	return hex.EncodeToString(hmacBytes([]byte(toSign), []byte(secret)))
}

func hmacBytes(toSign, secret []byte) []byte {
	_authSignature := hmac.New(sha256.New, secret)
	_authSignature.Write(toSign)
	return _authSignature.Sum(nil)
}

func checkSignature(result, secret string, body []byte) bool {
	expected := hmacBytes(body, []byte(secret))
	resultBytes, err := hex.DecodeString(result)

	if err != nil {
		return false
	}
	return hmac.Equal(expected, resultBytes)
}

func createAuthMap(key, secret, stringToSign string, sharedSecret string) map[string]string {
	authSignature := hmacSignature(stringToSign, secret)
	authString := strings.Join([]string{key, authSignature}, ":")
	if sharedSecret != "" {
		return map[string]string{"auth": authString, "shared_secret": sharedSecret}
	}
	return map[string]string{"auth": authString}
}

func md5Signature(body []byte) string {
	_bodyMD5 := md5.New()
	_bodyMD5.Write([]byte(body))
	return hex.EncodeToString(_bodyMD5.Sum(nil))
}

func encrypt(channel string, databytes []byte, encryptionKey string) string {
	sharedSecret := generateSharedSecret(channel, encryptionKey)
	nonce := generateNonce()
	nonceB64 := base64.StdEncoding.EncodeToString(nonce[:])
	cipherText := secretbox.Seal([]byte{}, databytes, &nonce, &sharedSecret)
	cipherTextB64 := base64.StdEncoding.EncodeToString(cipherText)
	return formatMessage(nonceB64, cipherTextB64)
}<commit_msg>rename databytes to data<commit_after>package pusher

import (
	"crypto/hmac"
	"crypto/md5"
	"crypto/rand"
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"errors"
	"fmt"
	"io"
	"strings"

	"golang.org/x/crypto/nacl/secretbox"
)

func hmacSignature(toSign, secret string) string {
	return hex.EncodeToString(hmacBytes([]byte(toSign), []byte(secret)))
}

func hmacBytes(toSign, secret []byte) []byte {
	_authSignature := hmac.New(sha256.New, secret)
	_authSignature.Write(toSign)
	return _authSignature.Sum(nil)
}

func checkSignature(result, secret string, body []byte) bool {
	expected := hmacBytes(body, []byte(secret))
	resultBytes, err := hex.DecodeString(result)

	if err != nil {
		return false
	}
	return hmac.Equal(expected, resultBytes)
}

func createAuthMap(key, secret, stringToSign string, sharedSecret string) map[string]string {
	authSignature := hmacSignature(stringToSign, secret)
	authString := strings.Join([]string{key, authSignature}, ":")
	if sharedSecret != "" {
		return map[string]string{"auth": authString, "shared_secret": sharedSecret}
	}
	return map[string]string{"auth": authString}
}

func md5Signature(body []byte) string {
	_bodyMD5 := md5.New()
	_bodyMD5.Write([]byte(body))
	return hex.EncodeToString(_bodyMD5.Sum(nil))
}

func encrypt(channel string, data []byte, encryptionKey string) string {
	sharedSecret := generateSharedSecret(channel, encryptionKey)
	nonce := generateNonce()
	nonceB64 := base64.StdEncoding.EncodeToString(nonce[:])
	cipherText := secretbox.Seal([]byte{}, data, &nonce, &sharedSecret)
	cipherTextB64 := base64.StdEncoding.EncodeToString(cipherText)
	return formatMessage(nonceB64, cipherTextB64)
}
{'fraction_non_alphanumeric': 0.1415236374585968, 'fraction_numerical': 0.015657934357121348, 'mean_word_length': 6.515837104072398, 'pattern_counts': {'":': 8, '<': 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': '4275625', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1125, 'n_words': 227}