a149bf48d2f7777cdd9366362680d66d023b909e
[platform/core/account/fido-asm.git] / common / uafv1tlvutil / src / StringTlvEncoder.cpp
1 /*
2  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include "StringTlvEncoder.h"
19 #include "Tlv.h"
20 #include "AsmHelper.h"
21 #include "AuthnrTypes.h"
22
23 StringTlvEncoder::StringTlvEncoder(void) {}
24
25 Buffer *
26 StringTlvEncoder::encode(const void *strTlv)
27 {
28         return NULL;
29 }
30
31 void*
32 StringTlvEncoder::decode(const uint8_t *rawData)
33 {
34         _INFO("StringTlvEncoder start");
35
36         RET_IF_FAIL(rawData != NULL, NULL);
37
38         tlv_s *tlv  = tlv_decode(rawData);
39         RET_IF_FAIL(tlv != NULL, NULL);
40
41         tlv->val = (uint8_t*)realloc(tlv->val, tlv->len + 1);
42         char *val = (char *)tlv->val;
43         val[tlv->len] = '\0';
44
45         _INFO("[%s]", val);
46
47         SAFE_DELETE(tlv);
48         _INFO("StringTlvEncoder end");
49         return val;
50 }