Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
md5.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2026 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
10/**
11 * @file md5.c
12 * @brief Implements OP_OPENSSL_MD5 to compute an MD5 hash in hexadecimal.
13 *
14 * Behavior:
15 * - Pops one value from the VM stack and converts it to a byte sequence by
16 * obtaining its string representation using value_to_string_alloc().
17 * - Computes the MD5 digest of the resulting bytes via fun_openssl_md5_hex()
18 * and pushes the lowercase hexadecimal string back onto the stack.
19 * - On allocation or hashing failure, pushes an empty string ("").
20 *
21 * Notes:
22 * - Non-string inputs are accepted; they are stringified first.
23 * - This snippet is included by vm.c and executed when OP_OPENSSL_MD5 is
24 * dispatched.
25 *
26 * Errors:
27 * - This opcode does not terminate the VM. Failures result in an empty
28 * string being pushed.
29 */
30
32 Value vdata = pop_value(vm);
33 char *s = value_to_string_alloc(&vdata);
34 free_value(vdata);
35 if (!s) {
36 push_value(vm, make_string(""));
37 break;
38 }
39 char *hex = fun_openssl_md5_hex((const unsigned char *)s, strlen(s));
41 if (!hex) {
42 push_value(vm, make_string(""));
43 break;
44 }
48 break;
49}
Value out
Definition apop.c:38
@ OP_OPENSSL_MD5
Definition bytecode.h:197
free_value(vdata)
free(s)
push_value(vm, out)
char * hex
Definition md5.c:39
static char * fun_openssl_md5_hex(const unsigned char *data, size_t len)
Compute MD5 digest and return it as a lowercase hex string.
Definition openssl.c:44
uint32_t s
Definition rol.c:31
Tagged union representing a Fun value.
Definition value.h:68
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
Definition value.c:95
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
Definition value.c:641
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition vm.c:580