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) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
23 #ifndef ASN1_CONSTRAINTS_VALIDATOR_H
24 #define ASN1_CONSTRAINTS_VALIDATOR_H
26 #include <asn_system.h> /* Platform-dependent types */
32 struct asn_TYPE_descriptor_s; /* Forward declaration */
35 * Validate the structure according to the ASN.1 constraints.
36 * If errbuf and errlen are given, they shall be pointing to the appropriate
37 * buffer space and its length before calling this function. Alternatively,
38 * they could be passed as NULL's. If constraints validation fails,
39 * errlen will contain the actual number of bytes taken from the errbuf
40 * to encode an error message (properly 0-terminated).
43 * This function returns 0 in case all ASN.1 constraints are met
44 * and -1 if one or more constraints were failed.
46 int asn_check_constraints(
47 const struct asn_TYPE_descriptor_s *type_descriptor,
48 const void *struct_ptr, /* Target language's structure */
49 char *errbuf, /* Returned error description */
50 size_t *errlen /* Length of the error description */
55 * Generic type for constraint checking callback,
56 * associated with every type descriptor.
58 typedef int(asn_constr_check_f)(
59 const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr,
60 asn_app_constraint_failed_f *optional_callback, /* Log the error */
61 void *optional_app_key /* Opaque key passed to a callback */
64 /*******************************
65 * INTERNALLY USEFUL FUNCTIONS *
66 *******************************/
68 asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */
69 asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */
72 * Invoke the callback with a complete error message.
74 #define ASN__CTFAIL if(ctfailcb) ctfailcb
80 #endif /* ASN1_CONSTRAINTS_VALIDATOR_H */