blob: 48d49e246a3ff3a2f0bcb81c0e42ba854bef28d9 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin1eded352006-07-13 11:19:01 +00002 * Copyright (c) 2004, 2006 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkinc6cac8e2016-03-14 02:57:07 -07005#ifndef ASN1_CONSTRAINTS_VALIDATOR_H
6#define ASN1_CONSTRAINTS_VALIDATOR_H
Lev Walkinf15320b2004-06-03 03:38:44 +00007
Lev Walkindc06f6b2004-10-20 15:50:55 +00008#include <asn_system.h> /* Platform-dependent types */
Lev Walkinf15320b2004-06-03 03:38:44 +00009
Lev Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkin5e033762004-09-29 13:26:15 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
Lev Walkinf15320b2004-06-03 03:38:44 +000015
16/*
17 * Validate the structure according to the ASN.1 constraints.
18 * If errbuf and errlen are given, they shall be pointing to the appropriate
19 * buffer space and its length before calling this function. Alternatively,
20 * they could be passed as NULL's. If constraints validation fails,
21 * errlen will contain the actual number of bytes taken from the errbuf
22 * to encode an error message (properly 0-terminated).
Lev Walkin1eded352006-07-13 11:19:01 +000023 *
24 * RETURN VALUES:
25 * This function returns 0 in case all ASN.1 constraints are met
26 * and -1 if one or more constraints were failed.
Lev Walkinf15320b2004-06-03 03:38:44 +000027 */
28int
Lev Walkin5e033762004-09-29 13:26:15 +000029asn_check_constraints(struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000030 const void *struct_ptr, /* Target language's structure */
31 char *errbuf, /* Returned error description */
32 size_t *errlen /* Length of the error description */
33 );
34
Lev Walkin1eded352006-07-13 11:19:01 +000035
Lev Walkinf15320b2004-06-03 03:38:44 +000036/*
37 * Generic type for constraint checking callback,
38 * associated with every type descriptor.
39 */
40typedef int (asn_constr_check_f)(
Lev Walkin5e033762004-09-29 13:26:15 +000041 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000042 const void *struct_ptr,
Lev Walkin1eded352006-07-13 11:19:01 +000043 asn_app_constraint_failed_f *optional_callback, /* Log the error */
44 void *optional_app_key /* Opaque key passed to a callback */
Lev Walkinf15320b2004-06-03 03:38:44 +000045 );
46
47/*******************************
48 * INTERNALLY USEFUL FUNCTIONS *
49 *******************************/
50
51asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */
52asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */
53
54/*
55 * Invoke the callback with a complete error message.
56 */
Lev Walkin7c1dc052016-03-14 03:08:15 -070057#define ASN__CTFAIL if(ctfailcb) ctfailcb
Lev Walkinf15320b2004-06-03 03:38:44 +000058
Lev Walkin21b41ac2005-07-24 09:03:44 +000059#ifdef __cplusplus
60}
61#endif
62
Lev Walkinc6cac8e2016-03-14 02:57:07 -070063#endif /* ASN1_CONSTRAINTS_VALIDATOR_H */