docs/system/ppc/ppce500: Add heading for networking chapter
[qemu.git] / crypto / der.h
blobe3d3aeacdcbf500b97a6f7c27a95638dd8fc294e
1 /*
2 * Copyright (c) 2022 Bytedance
3 * Author: lei he <helei.sig11@bytedance.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef QCRYPTO_ASN1_DECODER_H
21 #define QCRYPTO_ASN1_DECODER_H
23 #include "qapi/error.h"
25 /* Simple decoder used to parse DER encoded rsa keys. */
27 /**
28 * @opaque: user context.
29 * @value: the starting address of |value| part of 'Tag-Length-Value' pattern.
30 * @vlen: length of the |value|.
31 * Returns: 0 for success, any other value is considered an error.
33 typedef int (*QCryptoDERDecodeCb) (void *opaque, const uint8_t *value,
34 size_t vlen, Error **errp);
36 /**
37 * qcrypto_der_decode_int:
38 * @data: pointer to address of input data
39 * @dlen: pointer to length of input data
40 * @cb: callback invoked when decode succeed, if cb equals NULL, no
41 * callback will be invoked
42 * @opaque: parameter passed to cb
44 * Decode integer from DER-encoded data.
46 * Returns: On success, *data points to rest data, and *dlen
47 * will be set to the rest length of data, if cb is not NULL, must
48 * return 0 to make decode success, at last, the length of the data
49 * part of the decoded INTEGER will be returned. Otherwise, -1 is
50 * returned.
52 int qcrypto_der_decode_int(const uint8_t **data,
53 size_t *dlen,
54 QCryptoDERDecodeCb cb,
55 void *opaque,
56 Error **errp);
58 /**
59 * qcrypto_der_decode_seq:
61 * Decode sequence from DER-encoded data, similar with der_decode_int.
63 * @data: pointer to address of input data
64 * @dlen: pointer to length of input data
65 * @cb: callback invoked when decode succeed, if cb equals NULL, no
66 * callback will be invoked
67 * @opaque: parameter passed to cb
69 * Returns: On success, *data points to rest data, and *dlen
70 * will be set to the rest length of data, if cb is not NULL, must
71 * return 0 to make decode success, at last, the length of the data
72 * part of the decoded SEQUENCE will be returned. Otherwise, -1 is
73 * returned.
75 int qcrypto_der_decode_seq(const uint8_t **data,
76 size_t *dlen,
77 QCryptoDERDecodeCb cb,
78 void *opaque,
79 Error **errp);
81 #endif /* QCRYPTO_ASN1_DECODER_H */