<commit_before>package main

import (
	"crypto"
	"crypto/rand"
	"crypto/rsa"
	"crypto/sha256"
	"crypto/x509"
	"encoding/pem"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	"github.com/docker/vetinari/trustmanager"
	"github.com/endophage/gotuf/data"
	"github.com/spf13/viper"
)

type cliCryptoService struct {
	privateKeys map[string]*data.PrivateKey
	gun         string
}

func NewCryptoService(gun string) *cliCryptoService {
	return &cliCryptoService{privateKeys: make(map[string]*data.PrivateKey), gun: gun}
}

// Create is used to generate keys for targets, snapshots and timestamps
func (ccs *cliCryptoService) Create(role string) (*data.PublicKey, error) {
	_, cert, err := generateKeyAndCert(ccs.gun)
	if err != nil {
		return nil, err
	}

	// PEM ENcode the certificate, which will be put directly inside of TUF's root.json
	block := pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}
	pemdata := string(pem.EncodeToMemory(&block))

	return data.NewPublicKey("RSA", pemdata), nil
}

// Sign returns the signatures for data with the given keyIDs
func (ccs *cliCryptoService) Sign(keyIDs []string, payload []byte) ([]data.Signature, error) {
	// Create hasher and hash data
	hash := crypto.SHA256
	hashed := sha256.Sum256(payload)

	signatures := make([]data.Signature, 0, len(keyIDs))
	for _, kID := range keyIDs {<commit_msg>Add root certificate to trusted store<commit_after>package main

import (
	"crypto"
	"crypto/rand"
	"crypto/rsa"
	"crypto/sha256"
	"crypto/x509"
	"encoding/pem"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	"github.com/docker/vetinari/trustmanager"
	"github.com/endophage/gotuf/data"
	"github.com/spf13/viper"
)

type cliCryptoService struct {
	privateKeys map[string]*data.PrivateKey
	gun         string
}

func NewCryptoService(gun string) *cliCryptoService {
	return &cliCryptoService{privateKeys: make(map[string]*data.PrivateKey), gun: gun}
}

// Create is used to generate keys for targets, snapshots and timestamps
func (ccs *cliCryptoService) Create(role string) (*data.PublicKey, error) {
	_, cert, err := generateKeyAndCert(ccs.gun)
	if err != nil {
		return nil, err
	}

	// PEM ENcode the certificate, which will be put directly inside of TUF's root.json
	block := pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}
	pemdata := pem.EncodeToMemory(&block)

	// If this key has the role root, save it as a trusted certificate on our caStore
	if role == "root" {
		caStore.AddCertFromPEM(pemdata)
	}

	return data.NewPublicKey("RSA", string(pemdata)), nil
}

// Sign returns the signatures for data with the given keyIDs
func (ccs *cliCryptoService) Sign(keyIDs []string, payload []byte) ([]data.Signature, error) {
	// Create hasher and hash data
	hash := crypto.SHA256
	hashed := sha256.Sum256(payload)

	signatures := make([]data.Signature, 0, len(keyIDs))
	for _, kID := range keyIDs {
{'fraction_non_alphanumeric': 0.12756909992912827, 'fraction_numerical': 0.012756909992912827, 'mean_word_length': 4.657314629258517, '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': '3808145', 'n_tokens_mistral': 1046, 'n_tokens_neox': 993, 'n_words': 263}