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.
20 #include <asn_internal.h>
21 #include <constraints.h>
24 asn_generic_no_constraint(const asn_TYPE_descriptor_t *type_descriptor,
25 const void *struct_ptr,
26 asn_app_constraint_failed_f *cb, void *key) {
27 (void)type_descriptor; /* Unused argument */
28 (void)struct_ptr; /* Unused argument */
29 (void)cb; /* Unused argument */
30 (void)key; /* Unused argument */
32 /* Nothing to check */
37 asn_generic_unknown_constraint(const asn_TYPE_descriptor_t *type_descriptor,
38 const void *struct_ptr,
39 asn_app_constraint_failed_f *cb, void *key) {
40 (void)type_descriptor; /* Unused argument */
41 (void)struct_ptr; /* Unused argument */
42 (void)cb; /* Unused argument */
43 (void)key; /* Unused argument */
45 /* Unknown how to check */
50 const asn_TYPE_descriptor_t *failed_type;
51 const void *failed_struct_ptr;
57 _asn_i_ctfailcb(void *key, const asn_TYPE_descriptor_t *td, const void *sptr,
58 const char *fmt, ...) {
59 struct errbufDesc *arg = key;
64 arg->failed_type = td;
65 arg->failed_struct_ptr = sptr;
72 vlen = vsnprintf(arg->errbuf, maxlen, fmt, ap);
75 arg->errbuf[maxlen-1] = '\0'; /* Ensuring libc correctness */
76 arg->errlen = maxlen - 1; /* Not counting termination */
78 } else if(vlen >= 0) {
79 arg->errbuf[vlen] = '\0'; /* Ensuring libc correctness */
80 arg->errlen = vlen; /* Not counting termination */
83 * The libc on this system is broken.
85 vlen = sizeof("<broken vsnprintf>") - 1;
87 arg->errlen = vlen < maxlen ? vlen : maxlen;
88 memcpy(arg->errbuf, "<broken vsnprintf>", arg->errlen);
89 arg->errbuf[arg->errlen] = 0;
96 asn_check_constraints(const asn_TYPE_descriptor_t *type_descriptor,
97 const void *struct_ptr, char *errbuf, size_t *errlen) {
98 struct errbufDesc arg;
102 arg.failed_struct_ptr = 0;
104 arg.errlen = errlen ? *errlen : 0;
106 ret = type_descriptor->encoding_constraints.general_constraints(
107 type_descriptor, struct_ptr, _asn_i_ctfailcb, &arg);
108 if(ret == -1 && errlen) *errlen = arg.errlen;