Change log macro
[platform/core/connectivity/smartcard-service.git] / common / PKCS15DODF.cpp
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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 /* standard library header */
18
19 /* SLP library header */
20
21 /* local header */
22 #include "Debug.h"
23 #include "PKCS15DODF.h"
24 #include "SimpleTLV.h"
25
26 namespace smartcard_service_api
27 {
28 //      PKCS15DODF::PKCS15DODF():PKCS15Object()
29 //      {
30 //
31 //      }
32
33         PKCS15DODF::PKCS15DODF(unsigned int fid, Channel *channel):PKCS15Object(channel)
34         {
35                 int ret = 0;
36
37                 if ((ret = select(fid)) == 0)
38                 {
39                         ByteArray dodfData, extra;
40
41                         _DBG("response : %s", selectResponse.toString());
42
43                         if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
44                         {
45                                 _DBG("odfData : %s", dodfData.toString());
46
47                                 parseData(dodfData);
48                         }
49                         else
50                         {
51                                 _ERR("readBinary failed, [%d]", ret);
52                         }
53                 }
54                 else
55                 {
56                         _ERR("select failed, [%d]", ret);
57                 }
58         }
59
60         PKCS15DODF::PKCS15DODF(ByteArray path, Channel *channel):PKCS15Object(channel)
61         {
62                 int ret = 0;
63
64                 if ((ret = select(path)) == 0)
65                 {
66                         ByteArray dodfData, extra;
67
68                         _DBG("response : %s", selectResponse.toString());
69
70                         if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
71                         {
72                                 _DBG("dodfData : %s", dodfData.toString());
73
74                                 parseData(dodfData);
75                         }
76                         else
77                         {
78                                 _ERR("readBinary failed, [%d]", ret);
79                         }
80                 }
81                 else
82                 {
83                         _ERR("select failed, [%d]", ret);
84                 }
85         }
86
87         PKCS15DODF::~PKCS15DODF()
88         {
89         }
90
91         bool PKCS15DODF::parseData(ByteArray data)
92         {
93                 bool result = false;
94                 SimpleTLV tlv(data);
95
96                 while (tlv.decodeTLV())
97                 {
98                         switch (tlv.getTag())
99                         {
100                         case (unsigned int)0xA1 : /* CHOICE 1 : OidDO */
101                                 {
102                                         PKCS15OID oid(tlv.getValue());
103
104                                         _DBG("OID DataObject");
105
106                                         pair<ByteArray, PKCS15OID> newPair(oid.getOID(), oid);
107                                         mapOID.insert(newPair);
108                                 }
109                                 break;
110
111                         default :
112                                 _DBG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
113                                 break;
114                         }
115                 }
116
117                 _DBG("dataList.size() = %d", mapOID.size());
118
119                 return result;
120         }
121
122         int PKCS15DODF::searchOID(ByteArray oid, ByteArray &data)
123         {
124                 int result = -1;
125                 map<ByteArray, PKCS15OID>::iterator item;
126
127                 item = mapOID.find(oid);
128                 if (item != mapOID.end())
129                 {
130                         data = item->second.getPath();
131                         result = 0;
132                 }
133
134                 return result;
135         }
136
137 } /* namespace smartcard_service_api */