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 */
22 /* SLP library header */
26 #include "TLVHelper.h"
28 namespace smartcard_service_api
30 void TLVHelper::initialize(TLVHelper *parent)
40 TLVHelper::TLVHelper()
45 TLVHelper::TLVHelper(TLVHelper *parent)
50 TLVHelper::TLVHelper(const ByteArray &array)
55 TLVHelper::TLVHelper(const ByteArray &array, TLVHelper *parent)
57 setTLVBuffer(array, parent);
60 TLVHelper::~TLVHelper()
64 bool TLVHelper::setTLVBuffer(const ByteArray &array, TLVHelper *parent)
68 if (array.getLength() == 0)
76 bool TLVHelper::setTLVBuffer(unsigned char *buffer, unsigned int length, TLVHelper *parent)
78 return setTLVBuffer(ByteArray(buffer, length), parent);
81 bool TLVHelper::_decodeTLV()
87 currentV.releaseBuffer();
93 if ((result = decodeTag(tlvBuffer.getBuffer(offset))) < 0)
99 if ((result = decodeLength(tlvBuffer.getBuffer(offset))) < 0)
107 if ((result = decodeValue(tlvBuffer.getBuffer(offset))) < 0)
116 const char *TLVHelper::toString()
118 memset(strBuffer, 0, sizeof(strBuffer));
122 snprintf(strBuffer, sizeof(strBuffer), "T [%X], L [%d]", getTag(), getLength());
126 snprintf(strBuffer, sizeof(strBuffer), "T [%X], L [%d], V %s", getTag(), getLength(), getValue().toString());
132 TLVHelper *TLVHelper::getParentTLV()
137 bool TLVHelper::enterToValueTLV()
140 TLVHelper *temp = NULL;
142 if (getLength() >= 2)
144 temp = currentTLV->getChildTLV(getValue());
156 bool TLVHelper::returnToParentTLV()
160 // SCARD_DEBUG("current [%p], parent [%p]", currentTLV, currentTLV->getParentTLV());
162 if (currentTLV->getParentTLV() != NULL)
164 currentTLV = currentTLV->getParentTLV();
174 } /* namespace smartcard_service_api */