1/* Copyright (C) 2014 eperi GmbH.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16/******************************************************************//**
17@file Parser.h
18A structure and class to keep keys for encryption/decryption.
19
20Created 09/15/2014
21***********************************************************************/
22
23#include <my_crypt.h>
24#include <ctype.h>
25#include <map>
26#include <stdlib.h> /* size_t */
27
28struct keyentry {
29 unsigned int id;
30 unsigned char key[MY_AES_MAX_KEY_LENGTH];
31 unsigned int length;
32};
33
34class Parser
35{
36 const char *filename;
37 const char *filekey;
38 unsigned int line_number;
39
40 unsigned int from_hex(char c)
41 { return c <= '9' ? c - '0' : tolower(c) - 'a' + 10; }
42
43 void bytes_to_key(const unsigned char *salt, const char *secret,
44 unsigned char *key, unsigned char *iv);
45 bool read_filekey(const char *filekey, char *secret);
46 bool parse_file(std::map<unsigned int ,keyentry> *keys, const char *secret);
47 void report_error(const char *reason, size_t position);
48 int parse_line(char **line_ptr, keyentry *key);
49 char* read_and_decrypt_file(const char *secret);
50
51public:
52 Parser(const char* fn, const char *fk) :
53 filename(fn), filekey(fk), line_number(0) { }
54 bool parse(std::map<unsigned int ,keyentry> *keys);
55};
56