2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 /* standard library header */
19 /* SLP library header */
23 #include "PKCS15ODF.h"
24 #include "SimpleTLV.h"
25 #include "NumberStream.h"
27 namespace smartcard_service_api
29 PKCS15ODF::PKCS15ODF(Channel *channel) :
30 PKCS15Object(channel), dodf(NULL)
34 if ((ret = select(PKCS15ODF::ODF_FID)) >= SCARD_ERROR_OK)
36 ByteArray odfData, extra;
38 _DBG("response : %s", selectResponse.toString().c_str());
40 if ((ret = readBinary(0, 0, getFCP()->getFileSize(), odfData)) == 0)
42 _DBG("odfData : %s", odfData.toString().c_str());
48 _ERR("readBinary failed, [%d]", ret);
53 _ERR("select failed, [%d]", ret);
57 PKCS15ODF::PKCS15ODF(Channel *channel, const ByteArray &selectResponse) :
58 PKCS15Object(channel, selectResponse), dodf(NULL)
63 if ((ret = readBinary(0, 0, 0, odfData)) == 0)
65 _DBG("odfData : %s", odfData.toString().c_str());
71 _ERR("readBinary failed, [%d]", ret);
75 PKCS15ODF::~PKCS15ODF()
84 bool PKCS15ODF::parseData(const ByteArray &data)
89 while (tlv.decodeTLV())
93 case (unsigned int)0xA7 ://PKCS15ODF::TAG_DODF :
99 dodf = PKCS15Object::getOctetStream(tlv.getValue());
101 _DBG("path : %s", dodf.toString().c_str());
103 pair<unsigned int, ByteArray> newPair(tlv.getTag(), dodf);
104 dataList.insert(newPair);
108 case (unsigned int)0xA5 ://PKCS15ODF::TAG_TOKENINFO :
112 _DBG("TAG_TOKENINFO");
114 tokeninfo = PKCS15Object::getOctetStream(tlv.getValue());
116 _DBG("path : %s", tokeninfo.toString().c_str());
118 pair<unsigned int, ByteArray> newPair(tlv.getTag(), tokeninfo);
119 dataList.insert(newPair);
124 _DBG("Unknown tlv : t [%X], l [%d], v %s",
125 tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
131 _INFO("dataList.size() = %d", dataList.size());
136 PKCS15DODF *PKCS15ODF::getDODF()
138 map<unsigned int, ByteArray>::iterator item;
142 item = dataList.find((unsigned int)0xA7/*PKCS15ODF::TAG_DODF*/);
143 if (item != dataList.end())
145 NumberStream num(item->second);
146 unsigned int fid = num.getLittleEndianNumber();
148 _DBG("fid [%X]", fid);
150 dodf = new PKCS15DODF(fid, channel);
151 if (dodf != NULL && dodf->isClosed() == true)
153 _ERR("failed to open DODF");
161 _ERR("[%02X] is not found. total [%d]", TAG_DODF, dataList.size());
165 _DBG("dodf [%p]", dodf);
170 } /* namespace smartcard_service_api */