Add mbedtls dependency
This commit is contained in:
parent
f8b7a7755c
commit
b3441c109e
4 changed files with 57 additions and 0 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
||||||
[submodule "subprojects/munit"]
|
[submodule "subprojects/munit"]
|
||||||
path = subprojects/munit
|
path = subprojects/munit
|
||||||
url = https://github.com/nemequ/munit.git
|
url = https://github.com/nemequ/munit.git
|
||||||
|
[submodule "subprojects/mbedtls"]
|
||||||
|
path = subprojects/mbedtls
|
||||||
|
url = https://github.com/ARMmbed/mbedtls.git
|
||||||
|
|
|
@ -5,12 +5,18 @@ m_dep = cc.find_library('m', required : false)
|
||||||
|
|
||||||
incdir = include_directories('src')
|
incdir = include_directories('src')
|
||||||
|
|
||||||
|
cmake = import('cmake')
|
||||||
|
mbedtls_proj = cmake.subproject('mbedtls')
|
||||||
|
mbedtls_dep = mbedtls_proj.dependency('mbedtls')
|
||||||
|
|
||||||
executable('ex01', ['src/ex01/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
executable('ex01', ['src/ex01/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
||||||
executable('ex02', ['src/ex02/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
executable('ex02', ['src/ex02/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
||||||
executable('ex03', ['src/ex03/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
executable('ex03', ['src/ex03/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
||||||
executable('ex04', ['src/ex04/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
executable('ex04', ['src/ex04/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
||||||
executable('ex05', ['src/ex05/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
executable('ex05', ['src/ex05/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
||||||
executable('ex06', ['src/ex06/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
executable('ex06', ['src/ex06/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
||||||
|
executable('ex07', ['src/ex07/main.c', 'src/utils.c'],
|
||||||
|
dependencies: [m_dep, mbedtls_dep], include_directories: incdir)
|
||||||
|
|
||||||
munit_dep = dependency('munit', fallback: ['munit', 'munit_dep'])
|
munit_dep = dependency('munit', fallback: ['munit', 'munit_dep'])
|
||||||
|
|
||||||
|
|
47
src/ex07/main.c
Normal file
47
src/ex07/main.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#include "utils.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "mbedtls/aes.h"
|
||||||
|
|
||||||
|
#define BUF_SIZE 4096
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
printf("Usage: %s <key> <filename>\n", argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *key = argv[1];
|
||||||
|
const char *filename = argv[2];
|
||||||
|
|
||||||
|
FILE *fp = fopen(filename, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Error opening file %s\n", filename);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
char input[BUF_SIZE] = {'\0'};
|
||||||
|
size_t nread = fread(input, 1, BUF_SIZE, fp);
|
||||||
|
if (nread == 0) {
|
||||||
|
printf("Cannot read any character from file %s\n", filename);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char buf[BUF_SIZE] = {0};
|
||||||
|
size_t len = base64_to_bytes(buf, input);
|
||||||
|
if (len == 0) {
|
||||||
|
printf("Could not decode base64\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_aes_context aes;
|
||||||
|
|
||||||
|
if (fclose(fp)) {
|
||||||
|
printf("Error closing file %s\n", filename);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
1
subprojects/mbedtls
Submodule
1
subprojects/mbedtls
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 2a1d9332d55d1270084232e42df08fdb08129f1b
|
Loading…
Add table
Add a link
Reference in a new issue