1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 ******************************************************************/
27 PKIError DecodeLength(ByteArray *code, size_t *length)
30 CHECK_NULL_BYTE_ARRAY_PTR(code, PKI_NULL_PASSED);
32 CHECK_INC_BYTE_ARRAY_PTR(code, 1);
34 if ((*(code->data)) < LEN_LONG)
36 *length = *(code->data);
37 CHECK_INC_BYTE_ARRAY_PTR(code, 1);
42 uint8_t blocksNum = *(code->data) - LEN_LONG;
43 CHECK_INC_BYTE_ARRAY_PTR(code, 1);
44 CHECK_LESS(blocksNum, 5, PKI_WRONG_OCTET_LEN);
47 for (i = 0; i < blocksNum; ++i)
49 *length |= *(code->data) << ((blocksNum - i - 1) * SIZE_OF_BYTE);
50 CHECK_INC_BYTE_ARRAY_PTR(code, 1);
54 //should be: length <= array size
55 CHECK_LESS_EQUAL(*length, code->len, PKI_WRONG_OCTET_LEN);