2 * Copyright 2018 Intel Corporation
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.
16 // Author: Arun Kumar Sekar
20 TPM2_RC ConcatSizedByteBuffer( TPM2B_MAX_BUFFER *result, TPM2B *addBuffer )
24 if( ( result->size + addBuffer->size ) > TPM2_MAX_DIGEST_BUFFER )
25 return TSS2_SYS_RC_BAD_VALUE;
28 for( i = 0; i < addBuffer->size; i++ )
29 result->buffer[i + result->size] = addBuffer->buffer[i];
31 result->size += addBuffer->size;
33 return TPM2_RC_SUCCESS;
37 int saveDataToFile(const char *fileName, UINT8 *buf, UINT16 size)
41 if( fileName == NULL || buf == NULL || size == 0 )
44 f = fopen(fileName, "wb+");
46 printf("File(%s) open error.\n", fileName);
50 while( size > 0 && count > 0 ) {
51 count = fwrite(buf, 1, size, f);
57 printf("File write error\n");
66 int loadDataFromFile(const char *fileName, UINT8 *buf, UINT16 *size)
68 UINT16 count = 1, left;
70 if ( size == NULL || buf == NULL || fileName == NULL )
73 f = fopen(fileName, "rb+");
75 printf("File(%s) open error.\n", fileName);
81 while( left > 0 && count > 0 ) {
82 count = fread(buf, 1, left, f);
89 printf("File read error\n");