Toychain!
A toy blockchain in C
dataio.h File Reference

header for dataio.c More...

#include "lib/rsa.h"
#include "lib/sign.h"
Include dependency graph for dataio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cellKey
 
struct  cellProtected
 

Macros

#define BLOCK_STORAGE_DIR   "../data/"
 
#define BLOCKCHAIN_DIR   BLOCK_STORAGE_DIR "blockchain/"
 
#define PENDING_BLOCK_FILE   BLOCK_STORAGE_DIR "pending_block"
 
#define PENDING_VOTES_FILE   BLOCK_STORAGE_DIR "pending_votes.txt"
 

Typedefs

typedef struct cellKey CellKey
 
typedef struct cellProtected CellProtected
 

Functions

CellProtectedcreate_cell_protected (Protected *pr)
 Create a cell protected object. More...
 
void prepend_protected (CellProtected **list, Protected *pr)
 Prepend CellProtected to a list !!! takes ownership of pr. More...
 
CellProtectedread_protected (const char *filename)
 read protected list from file. data format is lines in protected_to_str format each representing a protected More...
 
void print_protected_list (CellProtected *list)
 prints the chained list of protected More...
 
CellProtectedcopy_protected_list (const CellProtected *o)
 copies the list of protected values. The copies order is inverted. More...
 
char * list_protected_to_str (const CellProtected *list)
 converts list of protected to a string. More...
 
CellProtectedstr_to_list_protected (const char *str)
 converts string to a list of protected More...
 
void free_cell_protected (CellProtected *c)
 correspond au delete_cell_protected dans le sujet More...
 
void free_list_protected (CellProtected *c)
 frees the list of pretected More...
 
void remove_fraudulent_declarations (CellProtected **list)
 removes fraudulent block from the chain. Fraudulent blocks are the ones that don't verify the signature. More...
 
void generate_random_data (int nv, int nc, const char *dir)
 generates nv public and private keys and prints them in ./{dir}/keys.txt. Chooses nc couple of keys among them and print them in ./{dir}/candidates.txt. Then for all nv public keys, assign a random public key from the previous nc couples converted using key_to_str(), and its signed version using sign(). Prints the results in ./{dir}/declarations.txt. More...
 
CellKeycreate_cell_key (Key *key)
 Allocate and initialize a CellKey object. More...
 
CellKeyinsert_cell_key (CellKey *cellkey, Key *key)
 Insert a new element to cellkey (head insertion). More...
 
CellKeyread_public_keys (char *file)
 Read the public keys of a file, return them in a CellKey structure. More...
 
void print_list_keys (CellKey *LCK)
 print the keys from a list More...
 
void free_cell_keys (CellKey *c)
 free a CellKey object(correspond to delete_cell_key in the subject). More...
 
void free_list_keys (CellKey *cellkey)
 free a list of keys More...
 
CellProtectedrand_list_protected (size_t len)
 generate random list of protected More...
 
CellProtectedrand_list_protected_range (size_t len, char low, char hi)
 generate random list of protected with message characters in range [low, hi]. More...
 
CellProtectedfuse_protected_lists (CellProtected *A, CellProtected *B)
 fusionner les liste A et B. Modifies A! More...
 
void delete_dir_files (const char *path)
 
void create_dir_structure ()
 

Detailed Description

header for dataio.c

Typedef Documentation

◆ CellKey

typedef struct cellKey CellKey

Structure for Key storing.

◆ CellProtected

typedef struct cellProtected CellProtected

Strucutre for Protected (declarations) storing.

Function Documentation

◆ copy_protected_list()

CellProtected * copy_protected_list ( const CellProtected o)

copies the list of protected values. The copies order is inverted.

Parameters
o
Returns
CellProtected*

◆ create_cell_key()

CellKey * create_cell_key ( Key key)

Allocate and initialize a CellKey object.

Parameters
keykey to assign
Returns
CellKey*

◆ create_cell_protected()

CellProtected * create_cell_protected ( Protected pr)

Create a cell protected object.

Parameters
pr
Returns
CellProtected*

◆ free_cell_keys()

void free_cell_keys ( CellKey c)

free a CellKey object(correspond to delete_cell_key in the subject).

Parameters
cCellkey object to delete

◆ free_cell_protected()

void free_cell_protected ( CellProtected c)

correspond au delete_cell_protected dans le sujet

Parameters
c

◆ free_list_keys()

void free_list_keys ( CellKey cellkey)

free a list of keys

Parameters
cellkey

◆ free_list_protected()

void free_list_protected ( CellProtected c)

frees the list of pretected

Parameters
c

◆ fuse_protected_lists()

CellProtected * fuse_protected_lists ( CellProtected A,
CellProtected B 
)

fusionner les liste A et B. Modifies A!

Parameters
A
B

◆ generate_random_data()

void generate_random_data ( int  nv,
int  nc,
const char *  dir 
)

generates nv public and private keys and prints them in ./{dir}/keys.txt. Chooses nc couple of keys among them and print them in ./{dir}/candidates.txt. Then for all nv public keys, assign a random public key from the previous nc couples converted using key_to_str(), and its signed version using sign(). Prints the results in ./{dir}/declarations.txt.

Parameters
nvnumber of couple of keys(citizen) to be generated
ncnumber of candidates among the nv couples

◆ insert_cell_key()

CellKey * insert_cell_key ( CellKey cellkey,
Key key 
)

Insert a new element to cellkey (head insertion).

Parameters
cellkeylist of key
keykey to insert
Returns
CellKey*

◆ list_protected_to_str()

char * list_protected_to_str ( const CellProtected list)

converts list of protected to a string.

Parameters
list
Returns
char*

◆ prepend_protected()

void prepend_protected ( CellProtected **  list,
Protected pr 
)

Prepend CellProtected to a list !!! takes ownership of pr.

Parameters
list
pr

◆ print_list_keys()

void print_list_keys ( CellKey LCK)

print the keys from a list

Parameters
LCKlist of keys

◆ print_protected_list()

void print_protected_list ( CellProtected list)

prints the chained list of protected

Parameters
list

◆ rand_list_protected()

CellProtected * rand_list_protected ( size_t  len)

generate random list of protected

Parameters
len
Returns
CellProtected*

◆ rand_list_protected_range()

CellProtected * rand_list_protected_range ( size_t  len,
char  low,
char  hi 
)

generate random list of protected with message characters in range [low, hi].

Parameters
len
low
hi
Returns
CellProtected*

◆ read_protected()

CellProtected * read_protected ( const char *  filename)

read protected list from file. data format is lines in protected_to_str format each representing a protected

Parameters
filename
Returns
CellProtected*

◆ read_public_keys()

CellKey * read_public_keys ( char *  file)

Read the public keys of a file, return them in a CellKey structure.

Parameters
filepath to the file
Returns
CellKey*

◆ remove_fraudulent_declarations()

void remove_fraudulent_declarations ( CellProtected **  list)

removes fraudulent block from the chain. Fraudulent blocks are the ones that don't verify the signature.

Parameters
list

◆ str_to_list_protected()

CellProtected * str_to_list_protected ( const char *  str)

converts string to a list of protected

Parameters
str
Returns
CellProtected*