Remove gcov rpm package
[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         /* LCOV_EXCL_START */
29         PKCS15DODF::PKCS15DODF(unsigned int fid, Channel *channel) :
30                 PKCS15Object(channel)
31         {
32                 int ret = 0;
33
34                 if ((ret = select(fid)) >= SCARD_ERROR_OK) {
35                         ByteArray dodfData, extra;
36
37                         _DBG("response : %s", selectResponse.toString().c_str());
38
39                         if ((ret = readBinaryAll(0, dodfData)) == 0) {
40                                 _DBG("dodfData : %s", dodfData.toString().c_str());
41
42                                 parseData(dodfData);
43                         } else {
44                                 _ERR("readBinary failed, [%d]", ret);
45                         }
46                 } else {
47                         _ERR("select failed, [%d]", ret);
48                 }
49         }
50
51         PKCS15DODF::PKCS15DODF(const ByteArray &path, Channel *channel) :
52                 PKCS15Object(channel)
53         {
54                 int ret = 0;
55
56                 if ((ret = select(path)) >= SCARD_ERROR_OK) {
57                         ByteArray dodfData, extra;
58
59                         _DBG("response : %s", selectResponse.toString().c_str());
60
61                         if ((ret = readBinaryAll(0, dodfData)) == 0) {
62                                 _DBG("dodfData : %s", dodfData.toString().c_str());
63
64                                 parseData(dodfData);
65                         } else {
66                                 _ERR("readBinary failed, [%d]", ret);
67                         }
68                 } else {
69                         _ERR("select failed, [%d]", ret);
70                 }
71         }
72
73         PKCS15DODF::~PKCS15DODF()
74         {
75         }
76
77         bool PKCS15DODF::parseData(const ByteArray &data)
78         {
79                 bool result = false;
80                 SimpleTLV tlv(data);
81
82                 while (tlv.decodeTLV()) {
83                         switch (tlv.getTag()) {
84                         case (unsigned int)0xA1 : /* CHOICE 1 : OidDO */
85                                 {
86                                         PKCS15OID oid(tlv.getValue());
87
88                                         _DBG("OID DataObject : %s", oid.getOID().toString().c_str());
89
90                                         mapOID.insert(make_pair(oid.getOID(), oid));
91                                 }
92                                 break;
93
94                         default :
95                                 _DBG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
96                                 break;
97                         }
98                 }
99
100                 _INFO("dataList.size() = %zu", mapOID.size());
101
102                 return result;
103         }
104
105         int PKCS15DODF::searchOID(const ByteArray &oid, ByteArray &data) const
106         {
107                 int result = -1;
108                 map<ByteArray, PKCS15OID>::const_iterator item;
109
110                 item = mapOID.find(oid);
111                 if (item != mapOID.end()) {
112                         data = item->second.getPath();
113                         result = 0;
114                 }
115
116                 return result;
117         }
118
119         /* LCOV_EXCL_STOP */
120 } /* namespace smartcard_service_api */