2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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 /* standard library header */
20 /* SLP library header */
24 #include "PKCS15ODF.h"
25 #include "SimpleTLV.h"
26 #include "NumberStream.h"
28 namespace smartcard_service_api
30 // PKCS15ODF::PKCS15ODF():PKCS15Object()
35 PKCS15ODF::PKCS15ODF(Channel *channel):PKCS15Object(channel), dodf(NULL)
39 if ((ret = select(PKCS15ODF::ODF_FID)) == 0)
41 ByteArray odfData, extra;
43 SCARD_DEBUG("response : %s", selectResponse.toString());
45 if ((ret = readBinary(0, 0, getFCP()->getFileSize(), odfData)) == 0)
47 SCARD_DEBUG("odfData : %s", odfData.toString());
53 SCARD_DEBUG_ERR("readBinary failed, [%d]", ret);
58 SCARD_DEBUG_ERR("select failed, [%d]", ret);
62 PKCS15ODF::PKCS15ODF(Channel *channel, ByteArray selectResponse):PKCS15Object(channel, selectResponse), dodf(NULL)
67 if ((ret = readBinary(0, 0, 0, odfData)) == 0)
69 SCARD_DEBUG("odfData : %s", odfData.toString());
75 SCARD_DEBUG_ERR("readBinary failed, [%d]", ret);
79 PKCS15ODF::~PKCS15ODF()
88 bool PKCS15ODF::parseData(ByteArray data)
93 while (tlv.decodeTLV())
97 case (unsigned int)0xA7 ://PKCS15ODF::TAG_DODF :
101 SCARD_DEBUG("TAG_DODF");
103 dodf = PKCS15Object::getOctetStream(tlv.getValue());
105 SCARD_DEBUG("path : %s", dodf.toString());
107 pair<unsigned int, ByteArray> newPair(tlv.getTag(), dodf);
108 dataList.insert(newPair);
112 case (unsigned int)0xA5 ://PKCS15ODF::TAG_TOKENINFO :
116 SCARD_DEBUG("TAG_TOKENINFO");
118 tokeninfo = PKCS15Object::getOctetStream(tlv.getValue());
120 SCARD_DEBUG("path : %s", tokeninfo.toString());
122 pair<unsigned int, ByteArray> newPair(tlv.getTag(), tokeninfo);
123 dataList.insert(newPair);
128 SCARD_DEBUG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
134 SCARD_DEBUG("dataList.size() = %d", dataList.size());
139 PKCS15DODF *PKCS15ODF::getDODF()
141 map<unsigned int, ByteArray>::iterator item;
145 item = dataList.find((unsigned int)0xA7/*PKCS15ODF::TAG_DODF*/);
146 if (item != dataList.end())
148 NumberStream num(item->second);
149 unsigned int fid = num.getLittleEndianNumber();
151 SCARD_DEBUG("fid [%X]", fid);
153 dodf = new PKCS15DODF(fid, channel);
154 if (dodf != NULL && dodf->isClosed() == true)
156 SCARD_DEBUG_ERR("failed to open DODF");
164 SCARD_DEBUG_ERR("[%02X] is not found. total [%d]", TAG_DODF, dataList.size());
168 SCARD_DEBUG("dodf [%p]", dodf);
173 } /* namespace smartcard_service_api */