<commit_before>package trousseau

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
)

type Trousseau struct {
	// Crypto public configuration attributes
	CryptoType      CryptoType      `json:"crypto_type"`
	CryptoAlgorithm CryptoAlgorithm `json:"crypto_algorithm"`

	// Encrypted data private attribute
	Data []byte `json:"_data"`

	// Crypto algorithm to decryption
	cryptoMapping map[CryptoAlgorithm]interface{}
}

func OpenTrousseau(fp string) (*Trousseau, error) {
	var trousseau *Trousseau
	var content []byte
	var err error

	content, err = ioutil.ReadFile(fp)
	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(content, &trousseau)
	if err != nil {
		return nil, err
	}

	return trousseau, nil
}

func (t *Trousseau) Decrypt() (*Store, error) {
	var store Store<commit_msg>Raise a proper error message when outdated data store format is detected [fix #109]<commit_after>package trousseau

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
)

type Trousseau struct {
	// Crypto public configuration attributes
	CryptoType      CryptoType      `json:"crypto_type"`
	CryptoAlgorithm CryptoAlgorithm `json:"crypto_algorithm"`

	// Encrypted data private attribute
	Data []byte `json:"_data"`

	// Crypto algorithm to decryption
	cryptoMapping map[CryptoAlgorithm]interface{}
}

func OpenTrousseau(fp string) (*Trousseau, error) {
	var trousseau *Trousseau
	var content []byte
	var err error

	content, err = ioutil.ReadFile(fp)
	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(content, &trousseau)
	if err != nil {
		// Check if the content of the file matches with a legacy
		// data store file format. Raise a proper error accordingly.
		contentVersion := DiscoverVersion(content, VersionDiscoverClosures)
		if contentVersion != "" {
			return nil, fmt.Errorf("outdated data store file format detected: %s. " +
								   "You are currently using incompatible version: %s. " +
								   "Please upgrade the data store by using the upgrade command.",
								   contentVersion, TROUSSEAU_VERSION)
		}
		return nil, err
	}

	return trousseau, nil
}

func (t *Trousseau) Decrypt() (*Store, error) {
	var store Store
{'fraction_non_alphanumeric': 0.10018639328984157, 'fraction_numerical': 0.0013979496738117428, 'mean_word_length': 3.9699074074074074, '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': '2701191', 'n_tokens_mistral': 730, 'n_tokens_neox': 657, 'n_words': 219}