1 /*############################################################################
2 # Copyright 2017 Intel Corporation
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 /// Implements ResizeOctStr
17 /*! \file */
18
19 #include "epid/member/src/resize.h"
20
21 #include <stdint.h>
22 #include "epid/common/src/memory.h"
23
ResizeOctStr(ConstOctStr a,size_t a_size,OctStr r,size_t r_size)24 EpidStatus ResizeOctStr(ConstOctStr a, size_t a_size, OctStr r, size_t r_size) {
25 if (!a || !a_size || !r || !r_size) return kEpidBadArgErr;
26 if (a_size <= r_size) {
27 memset(r, 0, r_size - a_size);
28 if (memcpy_S((uint8_t*)r + (r_size - a_size), a_size, a, a_size))
29 return kEpidErr;
30 } else {
31 size_t i;
32 for (i = 0; i < a_size - r_size; i++) {
33 if (((uint8_t*)a)[i])
34 return kEpidBadArgErr; // a does not fit into r_size
35 }
36 if (memcpy_S(r, r_size, (uint8_t*)a + (a_size - r_size), r_size))
37 return kEpidErr;
38 }
39 return kEpidNoErr;
40 }
41