Coverage Report

Created: 2026-10-16 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/asn1c/common/PrintableString.c
Line
Count
Source
1
/*-
2
 * Copyright (c) 2003, 2004, 2006 Lev Walkin <vlm@lionet.info>.
3
 * All rights reserved.
4
 * Redistribution and modifications are permitted subject to BSD license.
5
 */
6
#include <asn_internal.h>
7
#include <PrintableString.h>
8
9
/*
10
 * ASN.1:1984 (X.409)
11
 */
12
static const int _PrintableString_alphabet[256] = {
13
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /*                  */
14
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /*                  */
15
 1, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 5, 6, 7, 8, 9,  /* .      '() +,-./ */
16
10,11,12,13,14,15,16,17,18,19,20, 0, 0,21, 0,22,  /* 0123456789:  = ? */
17
 0,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,  /*  ABCDEFGHIJKLMNO */
18
38,39,40,41,42,43,44,45,46,47,48, 0, 0, 0, 0, 0,  /* PQRSTUVWXYZ      */
19
 0,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,  /*  abcdefghijklmno */
20
64,65,66,67,68,69,70,71,72,73,74, 0, 0, 0, 0, 0,  /* pqrstuvwxyz      */
21
};
22
static const int _PrintableString_code2value[74] = {
23
32,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54,
24
55,56,57,58,61,63,65,66,67,68,69,70,71,72,73,74,
25
75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
26
97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,
27
113,114,115,116,117,118,119,120,121,122};
28
29
/*
30
 * PrintableString basic type description.
31
 */
32
static const ber_tlv_tag_t asn_DEF_PrintableString_tags[] = {
33
    (ASN_TAG_CLASS_UNIVERSAL | (19 << 2)),  /* [UNIVERSAL 19] IMPLICIT ...*/
34
    (ASN_TAG_CLASS_UNIVERSAL | (4 << 2))    /* ... OCTET STRING */
35
};
36
#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
37
0
static int asn_DEF_PrintableString_v2c(unsigned int value) {
38
0
    return _PrintableString_alphabet[value > 255 ? 0 : value] - 1;
39
0
}
40
0
static int asn_DEF_PrintableString_c2v(unsigned int code) {
41
0
    if(code < 74)
42
0
        return _PrintableString_code2value[code];
43
0
    return -1;
44
0
}
45
static asn_per_constraints_t asn_DEF_PrintableString_per_constraints = {
46
    { APC_CONSTRAINED, 4, 4, 0x20, 0x39 },   /* Value */
47
    { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 },  /* Size */
48
    asn_DEF_PrintableString_v2c,
49
    asn_DEF_PrintableString_c2v
50
};
51
#endif  /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
52
asn_TYPE_operation_t asn_OP_PrintableString = {
53
    .kind = ASN_KIND_PRIMITIVE,
54
    OCTET_STRING_free,
55
#if !defined(ASN_DISABLE_PRINT_SUPPORT)
56
    OCTET_STRING_print_utf8,  /* ASCII subset */
57
#else
58
    0,
59
#endif  /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
60
    OCTET_STRING_compare,
61
    OCTET_STRING_copy,
62
#if !defined(ASN_DISABLE_BER_SUPPORT)
63
    OCTET_STRING_decode_ber,  /* Implemented in terms of OCTET STRING */
64
    OCTET_STRING_encode_der,
65
#else
66
    0,
67
    0,
68
#endif  /* !defined(ASN_DISABLE_BER_SUPPORT) */
69
#if !defined(ASN_DISABLE_XER_SUPPORT)
70
    OCTET_STRING_decode_xer_utf8,
71
    OCTET_STRING_encode_xer_utf8,
72
#else
73
    0,
74
    0,
75
#endif  /* !defined(ASN_DISABLE_XER_SUPPORT) */
76
#if !defined(ASN_DISABLE_JER_SUPPORT)
77
    OCTET_STRING_decode_jer_utf8,
78
    OCTET_STRING_encode_jer_utf8,
79
#else
80
    0,
81
    0,
82
#endif  /* !defined(ASN_DISABLE_JER_SUPPORT) */
83
#if !defined(ASN_DISABLE_OER_SUPPORT)
84
    OCTET_STRING_decode_oer,
85
    OCTET_STRING_encode_oer,
86
#else
87
    0,
88
    0,
89
#endif  /* !defined(ASN_DISABLE_OER_SUPPORT) */
90
#if !defined(ASN_DISABLE_UPER_SUPPORT)
91
    OCTET_STRING_decode_uper,
92
    OCTET_STRING_encode_uper,
93
#else
94
    0,
95
    0,
96
#endif  /* !defined(ASN_DISABLE_UPER_SUPPORT) */
97
#if !defined(ASN_DISABLE_APER_SUPPORT)
98
    OCTET_STRING_decode_aper,
99
    OCTET_STRING_encode_aper,
100
#else
101
    0,
102
    0,
103
#endif  /* !defined(ASN_DISABLE_APER_SUPPORT) */
104
#if !defined(ASN_DISABLE_RFILL_SUPPORT)
105
    OCTET_STRING_random_fill,
106
#else
107
    0,
108
#endif  /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
109
    0,  /* Use generic outmost tag fetcher */
110
#if !defined(ASN_DISABLE_CBOR_SUPPORT)
111
    OCTET_STRING_decode_cbor_utf8,
112
    OCTET_STRING_encode_cbor_utf8,
113
#else
114
    0,
115
    0,
116
#endif  /* !defined(ASN_DISABLE_CBOR_SUPPORT) */
117
};
118
asn_TYPE_descriptor_t asn_DEF_PrintableString = {
119
    "PrintableString",
120
    "PrintableString",
121
    &asn_OP_PrintableString,
122
    asn_DEF_PrintableString_tags,
123
    sizeof(asn_DEF_PrintableString_tags)
124
      / sizeof(asn_DEF_PrintableString_tags[0]) - 1,
125
    asn_DEF_PrintableString_tags,
126
    sizeof(asn_DEF_PrintableString_tags)
127
      / sizeof(asn_DEF_PrintableString_tags[0]),
128
    {
129
#if !defined(ASN_DISABLE_OER_SUPPORT)
130
        0,
131
#endif  /* !defined(ASN_DISABLE_OER_SUPPORT) */
132
#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
133
        &asn_DEF_PrintableString_per_constraints,
134
#endif  /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
135
#if !defined(ASN_DISABLE_JER_SUPPORT)
136
        0,
137
#endif  /* !defined(ASN_DISABLE_JER_SUPPORT) */
138
        PrintableString_constraint
139
    },
140
    0, 0,  /* No members */
141
    0  /* No specifics */
142
};
143
144
int
145
PrintableString_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
146
                           asn_app_constraint_failed_f *ctfailcb,
147
0
                           void *app_key) {
148
0
    const PrintableString_t *st = (const PrintableString_t *)sptr;
149
150
0
  if(st && st->buf) {
151
0
    uint8_t *buf = st->buf;
152
0
    uint8_t *end = buf + st->size;
153
154
    /*
155
     * Check the alphabet of the PrintableString.
156
     * ASN.1:1984 (X.409)
157
     */
158
0
    for(; buf < end; buf++) {
159
0
      if(!_PrintableString_alphabet[*buf]) {
160
0
        ASN__CTFAIL(app_key, td, sptr,
161
0
          "%s: value byte %ld (%d) "
162
0
          "not in PrintableString alphabet "
163
0
          "(%s:%d)",
164
0
          td->name,
165
0
          (long)((buf - st->buf) + 1),
166
0
          *buf,
167
0
          __FILE__, __LINE__);
168
0
        return -1;
169
0
      }
170
0
    }
171
0
  } else {
172
0
    ASN__CTFAIL(app_key, td, sptr,
173
0
      "%s: value not given (%s:%d)",
174
0
      td->name, __FILE__, __LINE__);
175
0
    return -1;
176
0
  }
177
178
0
  return 0;
179
0
}