blob: 3b17311018cba8fa5235144c54988ada0bf262ff [file] [log] [blame]
Harry Trana1b2b292019-10-28 11:07:23 -04001/*****************************************************************************
2# *
3# Copyright 2019 AT&T Intellectual Property *
4# *
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 *
8# *
9# http://www.apache.org/licenses/LICENSE-2.0 *
10# *
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. *
16# *
17******************************************************************************/
18
19/*-
20 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
22 */
23#ifndef ASN1_CONSTRAINTS_VALIDATOR_H
24#define ASN1_CONSTRAINTS_VALIDATOR_H
25
26#include <asn_system.h> /* Platform-dependent types */
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32struct asn_TYPE_descriptor_s; /* Forward declaration */
33
34/*
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).
41 *
42 * RETURN VALUES:
43 * This function returns 0 in case all ASN.1 constraints are met
44 * and -1 if one or more constraints were failed.
45 */
46int 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 */
51);
52
53
54/*
55 * Generic type for constraint checking callback,
56 * associated with every type descriptor.
57 */
58typedef 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 */
62);
63
64/*******************************
65 * INTERNALLY USEFUL FUNCTIONS *
66 *******************************/
67
68asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */
69asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */
70
71/*
72 * Invoke the callback with a complete error message.
73 */
74#define ASN__CTFAIL if(ctfailcb) ctfailcb
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif /* ASN1_CONSTRAINTS_VALIDATOR_H */