File: misc.h

package info (click to toggle)
jose 10-3%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,840 kB
  • sloc: ansic: 9,733; sh: 4,838; makefile: 157
file content (61 lines) | stat: -rw-r--r-- 1,587 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
/*
 * Copyright 2016 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "compat.h"

#include <jansson.h>
#include <stdbool.h>
#include <stdint.h>

#define KEYMAX 1024

#define containerof(ptr, type, member) \
    ((type *)((char *) ptr - offsetof(type, member)))

#define declare_cleanup_full(type, prfx) \
    static inline void \
    type ## _auto(type **p) { \
        if (!p) return; \
        prfx ## _free(*p); \
        *p = NULL; \
    }

#define declare_cleanup(type) declare_cleanup_full(type, type)

#define openssl_auto(type) type __attribute__((cleanup(type ## _auto)))

declare_cleanup_full(BIGNUM, BN_clear)

size_t
str2enum(const char *str, ...);

BIGNUM *
bn_decode(const uint8_t buf[], size_t len);

BIGNUM *
bn_decode_json(const json_t *json);

bool
bn_encode(const BIGNUM *bn, uint8_t buf[], size_t len);

json_t *
bn_encode_json(const BIGNUM *bn, size_t len);

bool
add_entity(json_t *root, json_t *obj, const char *plural, ...);