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 */
21 /* SLP library header */
25 #include "TLVHelper.h"
27 namespace smartcard_service_api
29 void TLVHelper::initialize(TLVHelper *parent)
39 TLVHelper::TLVHelper()
44 TLVHelper::TLVHelper(TLVHelper *parent)
49 TLVHelper::TLVHelper(const ByteArray &array)
54 TLVHelper::TLVHelper(const ByteArray &array, TLVHelper *parent)
56 setTLVBuffer(array, parent);
59 TLVHelper::~TLVHelper()
63 bool TLVHelper::setTLVBuffer(const ByteArray &array, TLVHelper *parent)
67 if (array.getLength() == 0)
75 bool TLVHelper::setTLVBuffer(unsigned char *buffer, unsigned int length, TLVHelper *parent)
77 return setTLVBuffer(ByteArray(buffer, length), parent);
80 bool TLVHelper::_decodeTLV()
86 currentV.releaseBuffer();
92 if ((result = decodeTag(tlvBuffer.getBuffer(offset))) < 0)
98 if ((result = decodeLength(tlvBuffer.getBuffer(offset))) < 0)
106 if ((result = decodeValue(tlvBuffer.getBuffer(offset))) < 0)
115 const char *TLVHelper::toString()
117 memset(strBuffer, 0, sizeof(strBuffer));
121 snprintf(strBuffer, sizeof(strBuffer), "T [%X], L [%d]", getTag(), getLength());
125 snprintf(strBuffer, sizeof(strBuffer), "T [%X], L [%d], V %s", getTag(), getLength(), getValue().toString());
131 TLVHelper *TLVHelper::getParentTLV()
136 bool TLVHelper::enterToValueTLV()
139 TLVHelper *temp = NULL;
141 if (getLength() >= 2)
143 temp = currentTLV->getChildTLV(getValue());
155 bool TLVHelper::returnToParentTLV()
159 // SCARD_DEBUG("current [%p], parent [%p]", currentTLV, currentTLV->getParentTLV());
161 if (currentTLV->getParentTLV() != NULL)
163 currentTLV = currentTLV->getParentTLV();
173 } /* namespace smartcard_service_api */