File: build

package info (click to toggle)
mbedtls 2.4.2-1%2Bdeb9u3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,208 kB
  • sloc: ansic: 66,438; sh: 5,507; perl: 1,440; cpp: 1,183; makefile: 785; tcl: 4
file content (47 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
# autopkgtest check: Build and run a very simple program against mbedtls

set -e

# Require $ADTTMP for temporary build files
if [ -z "$ADTTMP" ]
then
	echo "Required envvar \"$ADTTMP\"is not set" >&2
	exit 1
fi

cd "$ADTTMP"
cat <<EOF > mbedtls_sha1.c
#include <mbedtls/md.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
    unsigned char output[20];
    int i;

    if (mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1),
	    (unsigned char*) argv[1], strlen(argv[1]), output) != 0)
    {
        fputs("mbedtls_md failed", stderr);
        return 1;
    }

    for (i = 0; i < sizeof(output); i++)
        printf("%02x", output[i]);

    printf("\n");
    return 0;
}
EOF

# Build program
gcc -Wall -Werror -o mbedtls_sha1 mbedtls_sha1.c -lmbedcrypto
echo "build: OK"

# Run it on a few strings
[ $(./mbedtls_sha1 '')    = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' ]
echo "run1: OK"
[ $(./mbedtls_sha1 hello) = 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d' ]
echo "run2: OK"