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.
18 #include "PKCS15ODF.h"
19 #include "SimpleTLV.h"
20 #include "NumberStream.h"
22 namespace smartcard_service_api
24 PKCS15ODF::PKCS15ODF(Channel *channel) :
25 PKCS15Object(channel), dodf(NULL)
29 if ((ret = select(PKCS15ODF::ODF_FID)) >= SCARD_ERROR_OK)
31 ByteArray odfData, extra;
33 _DBG("response : %s", selectResponse.toString().c_str());
35 if ((ret = readBinary(0, 0, getFCP()->getFileSize(), odfData)) == 0)
37 _DBG("odfData : %s", odfData.toString().c_str());
43 _ERR("readBinary failed, [%d]", ret);
48 _ERR("select failed, [%d]", ret);
52 PKCS15ODF::PKCS15ODF(Channel *channel, const ByteArray &selectResponse) :
53 PKCS15Object(channel, selectResponse), dodf(NULL)
58 if ((ret = readBinary(0, 0, 0, odfData)) == 0)
60 _DBG("odfData : %s", odfData.toString().c_str());
66 _ERR("readBinary failed, [%d]", ret);
70 PKCS15ODF::~PKCS15ODF()
79 bool PKCS15ODF::parseData(const ByteArray &data)
84 while (tlv.decodeTLV())
88 case (unsigned int)0xA7 ://PKCS15ODF::TAG_DODF :
94 dodf = PKCS15Object::getOctetStream(tlv.getValue());
96 _DBG("path : %s", dodf.toString().c_str());
98 pair<unsigned int, ByteArray> newPair(tlv.getTag(), dodf);
99 dataList.insert(newPair);
103 case (unsigned int)0xA5 ://PKCS15ODF::TAG_TOKENINFO :
107 _DBG("TAG_TOKENINFO");
109 tokeninfo = PKCS15Object::getOctetStream(tlv.getValue());
111 _DBG("path : %s", tokeninfo.toString().c_str());
113 pair<unsigned int, ByteArray> newPair(tlv.getTag(), tokeninfo);
114 dataList.insert(newPair);
119 _DBG("Unknown tlv : t [%X], l [%d], v %s",
120 tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
126 _INFO("dataList.size() = %d", dataList.size());
131 PKCS15DODF *PKCS15ODF::getDODF()
133 map<unsigned int, ByteArray>::iterator item;
137 item = dataList.find((unsigned int)0xA7/*PKCS15ODF::TAG_DODF*/);
138 if (item != dataList.end())
140 NumberStream num(item->second);
141 unsigned int fid = num.getLittleEndianNumber();
143 _DBG("fid [%X]", fid);
145 dodf = new PKCS15DODF(fid, channel);
146 if (dodf != NULL && dodf->isClosed() == true)
148 _ERR("failed to open DODF");
156 _ERR("[%02X] is not found. total [%d]", TAG_DODF, dataList.size());
160 _DBG("dodf [%p]", dodf);
165 } /* namespace smartcard_service_api */