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 "PKCS15DODF.h"
19 #include "SimpleTLV.h"
21 namespace smartcard_service_api
23 PKCS15DODF::PKCS15DODF(unsigned int fid, Channel *channel) :
28 if ((ret = select(fid)) >= SCARD_ERROR_OK)
30 ByteArray dodfData, extra;
32 _DBG("response : %s", selectResponse.toString().c_str());
34 if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
36 _DBG("odfData : %s", dodfData.toString().c_str());
42 _ERR("readBinary failed, [%d]", ret);
47 _ERR("select failed, [%d]", ret);
51 PKCS15DODF::PKCS15DODF(const ByteArray &path, Channel *channel) :
56 if ((ret = select(path)) >= SCARD_ERROR_OK)
58 ByteArray dodfData, extra;
60 _DBG("response : %s", selectResponse.toString().c_str());
62 if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
64 _DBG("dodfData : %s", dodfData.toString().c_str());
70 _ERR("readBinary failed, [%d]", ret);
75 _ERR("select failed, [%d]", ret);
79 PKCS15DODF::~PKCS15DODF()
83 bool PKCS15DODF::parseData(const ByteArray &data)
88 while (tlv.decodeTLV())
92 case (unsigned int)0xA1 : /* CHOICE 1 : OidDO */
94 PKCS15OID oid(tlv.getValue());
96 _DBG("OID DataObject : %s", oid.getOID().toString().c_str());
98 mapOID.insert(make_pair(oid.getOID(), oid));
103 _DBG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
108 _INFO("dataList.size() = %d", mapOID.size());
113 int PKCS15DODF::searchOID(const ByteArray &oid, ByteArray &data) const
116 map<ByteArray, PKCS15OID>::const_iterator item;
118 item = mapOID.find(oid);
119 if (item != mapOID.end())
121 data = item->second.getPath();
128 } /* namespace smartcard_service_api */