Adding signature checking
[platform/core/system/tizen-platform-wrapper.git] / src / hashing.c
1 /*
2  * Copyright (C) 2013-2014 Intel Corporation.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors:
19  *   José Bollo <jose.bollo@open.eurogiciel.org>
20  *   Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
21  *   Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
22  *
23  */
24 #define _GNU_SOURCE
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <string.h>
31 #include <assert.h>
32
33 #include "tzplatform_variables.h"
34 #include "hash.inc"
35
36 static const char *var_names[_TZPLATFORM_VARIABLES_COUNT_];
37
38 inline int hashid(const char *text, unsigned int len)
39 {
40     const struct varassoc *vara = hashvar(text, len);
41     return vara ? vara->id : -1;
42 }
43
44 const char *keyname(int id)
45 {
46     const struct varassoc *iter, *end;
47
48     assert(0 <= id && id < _TZPLATFORM_VARIABLES_COUNT_);
49     if (!var_names[0]) {
50         iter = namassoc;
51         end = iter + (sizeof namassoc / sizeof namassoc[0]);
52         while (iter != end) {
53             if (iter->offset >= 0) {
54                 assert(0 <= iter->id && iter->id < _TZPLATFORM_VARIABLES_COUNT_);
55                 var_names[iter->id] = varpool + iter->offset;
56             }
57             iter++;
58         }
59     }
60     return var_names[id];
61 }
62