resize.c 1.4 KB

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