1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
5 # Licensed under the Apache License, Version 2.0 (the "License"); *
6 # you may not use this file except in compliance with the License. *
7 # You may obtain a copy of the License at *
9 # http://www.apache.org/licenses/LICENSE-2.0 *
11 # Unless required by applicable law or agreed to in writing, software *
12 # distributed under the License is distributed on an "AS IS" BASIS, *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 # See the License for the specific language governing permissions and *
15 # limitations under the License. *
17 ******************************************************************************/
20 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
23 #ifndef _DER_ENCODER_H_
24 #define _DER_ENCODER_H_
26 #include <asn_application.h>
32 struct asn_TYPE_descriptor_s; /* Forward declaration */
35 * The DER encoder of any type. May be invoked by the application.
36 * Produces DER- and BER-compliant encoding. (DER is a subset of BER).
38 * NOTE: Use the ber_decode() function (ber_decoder.h) to decode data
39 * produced by der_encode().
41 asn_enc_rval_t der_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
42 const void *struct_ptr, /* Structure to be encoded */
43 asn_app_consume_bytes_f *consume_bytes_cb,
44 void *app_key /* Arbitrary callback argument */
47 /* A variant of der_encode() which encodes data into the pre-allocated buffer */
48 asn_enc_rval_t der_encode_to_buffer(
49 const struct asn_TYPE_descriptor_s *type_descriptor,
50 const void *struct_ptr, /* Structure to be encoded */
51 void *buffer, /* Pre-allocated buffer */
52 size_t buffer_size /* Initial buffer size (maximum) */
56 * Type of the generic DER encoder.
58 typedef asn_enc_rval_t(der_type_encoder_f)(
59 const struct asn_TYPE_descriptor_s *type_descriptor,
60 const void *struct_ptr, /* Structure to be encoded */
61 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
62 ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
63 void *app_key /* Arbitrary callback argument */
67 /*******************************
68 * INTERNALLY USEFUL FUNCTIONS *
69 *******************************/
72 * Write out leading TL[v] sequence according to the type definition.
74 ssize_t der_write_tags(const struct asn_TYPE_descriptor_s *type_descriptor,
76 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
77 int last_tag_form, /* {0,!0}: prim, constructed */
79 asn_app_consume_bytes_f *consume_bytes_cb,
86 #endif /* _DER_ENCODER_H_ */