| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <stdbool.h> |
| 19 |
#include <stdint.h> |
| 20 |
|
| 21 |
#include "utils/s2n_result.h" |
| 22 |
|
| 23 |
struct s2n_blob { |
| 24 |
|
| 25 |
uint8_t *data; |
| 26 |
|
| 27 |
|
| 28 |
uint32_t size; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
uint32_t allocated; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
unsigned growable : 1; |
| 49 |
}; |
| 50 |
|
| 51 |
bool s2n_blob_is_growable(const struct s2n_blob *b); |
| 52 |
S2N_RESULT s2n_blob_validate(const struct s2n_blob *b); |
| 53 |
int S2N_RESULT_MUST_USE s2n_blob_init(struct s2n_blob *b, uint8_t *data, uint32_t size); |
| 54 |
int s2n_blob_zero(struct s2n_blob *b); |
| 55 |
int S2N_RESULT_MUST_USE s2n_blob_char_to_lower(struct s2n_blob *b); |
| 56 |
int S2N_RESULT_MUST_USE s2n_blob_slice(const struct s2n_blob *b, struct s2n_blob *slice, uint32_t offset, uint32_t size); |
| 57 |
|
| 58 |
#define s2n_stack_blob(name, requested_size, maximum) \ |
| 59 |
size_t name##_requested_size = (requested_size); \ |
| 60 |
uint8_t name##_buf[(maximum)] = { 0 }; \ |
| 61 |
POSIX_ENSURE_LTE(name##_requested_size, (maximum)); \ |
| 62 |
struct s2n_blob name = { 0 }; \ |
| 63 |
POSIX_GUARD(s2n_blob_init(&name, name##_buf, name##_requested_size)) |
| 64 |
|
| 65 |
#define RESULT_STACK_BLOB(name, requested_size, maximum) \ |
| 66 |
size_t name##_requested_size = (requested_size); \ |
| 67 |
uint8_t name##_buf[(maximum)] = { 0 }; \ |
| 68 |
RESULT_ENSURE_LTE(name##_requested_size, (maximum)); \ |
| 69 |
struct s2n_blob name = { 0 }; \ |
| 70 |
RESULT_GUARD_POSIX(s2n_blob_init(&name, name##_buf, name##_requested_size)) |
| 71 |
|
| 72 |
#define S2N_BLOB_LABEL(name, str) \ |
| 73 |
static uint8_t name##_data[] = str; \ |
| 74 |
const struct s2n_blob name = { .data = name##_data, .size = sizeof(name##_data) - 1 }; |