<commit_before>package store

import (
	"crypto/x509"
	"errors"
	"fmt"
	"os/exec"
	"path/filepath"
	"strings"

	"github.com/adamdecaf/cert-manage/pkg/certutil"
	"github.com/adamdecaf/cert-manage/pkg/file"
	"github.com/adamdecaf/cert-manage/pkg/whitelist"
)

var (
	openSSLCertPaths = []string{
		"/usr/local/etc/openssl/certs", // Darwin/OSX
	}

	openSSLRehashPaths = []string{
		"/usr/local/opt/openssl/bin/c_rehash", // Darwin/OSX
	}
)

type opensslStore struct{}

func OpenSSLStore() Store {
	return opensslStore{}
}

func (s opensslStore) Add(certs []*x509.Certificate) error {
	dir, err := s.findCertPath()
	if err != nil {
		return err
	}

	for i := range certs {
		fp := certutil.GetHexSHA256Fingerprint(*certs[i])
		path := filepath.Join(dir, fmt.Sprintf("%s.crt", fp))
		err = certutil.ToFile(path, certs[i:i+1])
		if err != nil {
			return err
		}
	}
	if len(certs) > 0 {
		return s.rehash()
	}<commit_msg>store/openssl: add ubuntu openssl paths<commit_after>package store

import (
	"crypto/x509"
	"errors"
	"fmt"
	"os/exec"
	"path/filepath"
	"strings"

	"github.com/adamdecaf/cert-manage/pkg/certutil"
	"github.com/adamdecaf/cert-manage/pkg/file"
	"github.com/adamdecaf/cert-manage/pkg/whitelist"
)

var (
	openSSLCertPaths = []string{
		"/etc/ssl/certs/ca-certificates.crt", // Ubuntu
		"/usr/local/etc/openssl/certs", // Darwin/OSX
	}

	openSSLRehashPaths = []string{
		"/usr/bin/c_rehash", // Ubuntu
		"/usr/local/opt/openssl/bin/c_rehash", // Darwin/OSX
	}
)

type opensslStore struct{}

func OpenSSLStore() Store {
	return opensslStore{}
}

func (s opensslStore) Add(certs []*x509.Certificate) error {
	dir, err := s.findCertPath()
	if err != nil {
		return err
	}

	for i := range certs {
		fp := certutil.GetHexSHA256Fingerprint(*certs[i])
		path := filepath.Join(dir, fmt.Sprintf("%s.crt", fp))
		err = certutil.ToFile(path, certs[i:i+1])
		if err != nil {
			return err
		}
	}
	if len(certs) > 0 {
		return s.rehash()
	}
{'fraction_non_alphanumeric': 0.16846986089644514, 'fraction_numerical': 0.011334363730036065, 'mean_word_length': 3.748166259168704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7279557', 'n_tokens_mistral': 868, 'n_tokens_neox': 791, 'n_words': 140}