2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
24 #define _POSIX_C_SOURCE 200809L
30 #include <openssl/bio.h>
32 #include <yaca_crypto.h>
33 #include <yaca_error.h>
37 void dump_hex(const char *buf, size_t dump_size, const char *fmt, ...)
45 BIO_dump_fp(stdout, buf, dump_size);
48 void debug_func(const char *buf)
53 int write_file(const char *path, char *data, size_t data_len)
62 while (written != data_len) {
63 int ret = fwrite(data + written, 1, data_len - written, f);
79 int read_file(const char *path, char **data, size_t *data_len)
92 size_t read = fread(tmp, 1, BUF_SIZE, f);
95 if (yaca_realloc(buf_len + read, (void**)&buf) != YACA_ERROR_NONE) {
100 memcpy(buf + buf_len, tmp, read);
104 if (ferror(f) != 0) {
123 int read_stdin_line(const char *prompt, char **string)
130 printf("%s", prompt);
132 read = getline(&buf, &size, stdin);
138 if (yaca_realloc(read, (void**)&buf) != YACA_ERROR_NONE) {
142 buf[read - 1] = '\0';