Add rule for 'All devices apps' when access rule is empty.
[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 #include "Debug.h"
18 #include "PKCS15DODF.h"
19 #include "SimpleTLV.h"
20
21 namespace smartcard_service_api
22 {
23         PKCS15DODF::PKCS15DODF(unsigned int fid, Channel *channel) :
24                 PKCS15Object(channel)
25         {
26                 int ret = 0;
27
28                 if ((ret = select(fid)) >= SCARD_ERROR_OK)
29                 {
30                         ByteArray dodfData, extra;
31
32                         _DBG("response : %s", selectResponse.toString().c_str());
33
34                         if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
35                         {
36                                 _DBG("odfData : %s", dodfData.toString().c_str());
37
38                                 parseData(dodfData);
39                         }
40                         else
41                         {
42                                 _ERR("readBinary failed, [%d]", ret);
43                         }
44                 }
45                 else
46                 {
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                 {
58                         ByteArray dodfData, extra;
59
60                         _DBG("response : %s", selectResponse.toString().c_str());
61
62                         if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
63                         {
64                                 _DBG("dodfData : %s", dodfData.toString().c_str());
65
66                                 parseData(dodfData);
67                         }
68                         else
69                         {
70                                 _ERR("readBinary failed, [%d]", ret);
71                         }
72                 }
73                 else
74                 {
75                         _ERR("select failed, [%d]", ret);
76                 }
77         }
78
79         PKCS15DODF::~PKCS15DODF()
80         {
81         }
82
83         bool PKCS15DODF::parseData(const ByteArray &data)
84         {
85                 bool result = false;
86                 SimpleTLV tlv(data);
87
88                 while (tlv.decodeTLV())
89                 {
90                         switch (tlv.getTag())
91                         {
92                         case (unsigned int)0xA1 : /* CHOICE 1 : OidDO */
93                                 {
94                                         PKCS15OID oid(tlv.getValue());
95
96                                         _DBG("OID DataObject : %s", oid.getOID().toString().c_str());
97
98                                         mapOID.insert(make_pair(oid.getOID(), oid));
99                                 }
100                                 break;
101
102                         default :
103                                 _DBG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
104                                 break;
105                         }
106                 }
107
108                 _INFO("dataList.size() = %d", mapOID.size());
109
110                 return result;
111         }
112
113         int PKCS15DODF::searchOID(const ByteArray &oid, ByteArray &data) const
114         {
115                 int result = -1;
116                 map<ByteArray, PKCS15OID>::const_iterator item;
117
118                 item = mapOID.find(oid);
119                 if (item != mapOID.end())
120                 {
121                         data = item->second.getPath();
122                         result = 0;
123                 }
124
125                 return result;
126         }
127
128 } /* namespace smartcard_service_api */