tizen 2.3 release
[framework/web/wearable/wrt-security.git] / ace / dao / AceDAOConversions.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  *
18  *
19  * @file       AceDaoConversions.h
20  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
21  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
22  * @version    0.1
23  * @brief
24  */
25
26 #include <openssl/md5.h>
27 #include <dpl/foreach.h>
28
29 #include <ace-dao-ro/AceDAOConversions.h>
30
31 namespace AceDB {
32
33 DPL::String AceDaoConversions::convertToHash(const BaseAttributeSet &attributes)
34 {
35     unsigned char attrHash[MD5_DIGEST_LENGTH];
36     std::string attrString;
37     FOREACH(it, attributes) {
38         // [CR] implementation of it->toString() is not secure, 24.03.2010
39         attrString.append((*it)->toString());
40     }
41
42     MD5((unsigned char *) attrString.c_str(), attrString.length(), attrHash);
43
44     char attrHashCoded[MD5_DIGEST_LENGTH*2 + 1];
45     for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
46         snprintf(&attrHashCoded[i << 1], 3,
47                 "%02X",
48                 static_cast<int>(attrHash[i]));
49     }
50     return DPL::FromASCIIString(attrHashCoded);
51 }
52
53
54 }