Coverage Report

Created: 2026-09-28 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/asn1c/common/NativeInteger_aper.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2017 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 <NativeInteger.h>
8
9
asn_dec_rval_t
10
NativeInteger_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
11
                          const asn_TYPE_descriptor_t *td,
12
162k
                          const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
13
14
162k
    const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
15
162k
    asn_dec_rval_t rval;
16
162k
    long *native = (long *)*sptr;
17
162k
    INTEGER_t tmpint;
18
162k
    void *tmpintptr = &tmpint;
19
20
162k
    (void)opt_codec_ctx;
21
162k
    ASN_DEBUG("Decoding NativeInteger %s (APER)", td->name);
22
23
162k
    if(!native) {
24
6.10k
        native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
25
6.10k
        if(!native) ASN__DECODE_FAILED;
26
6.10k
    }
27
28
162k
    memset(&tmpint, 0, sizeof tmpint);
29
162k
    rval = INTEGER_decode_aper(opt_codec_ctx, td, constraints,
30
162k
                               &tmpintptr, pd);
31
162k
    if(rval.code == RC_OK) {
32
161k
        if((specs&&specs->field_unsigned)
33
161k
                ? asn_INTEGER2ulong(&tmpint, (unsigned long *)native)
34
161k
                : asn_INTEGER2long(&tmpint, native))
35
39
            rval.code = RC_FAIL;
36
161k
        else
37
161k
            ASN_DEBUG("NativeInteger %s got value %ld",
38
161k
                      td->name, *native);
39
161k
    }
40
162k
    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
41
42
162k
    return rval;
43
162k
}
44
45
asn_enc_rval_t
46
NativeInteger_encode_aper(const asn_TYPE_descriptor_t *td,
47
                          const asn_per_constraints_t *constraints,
48
0
                          const void *sptr, asn_per_outp_t *po) {
49
50
0
    const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
51
0
    asn_enc_rval_t er = {0,0,0};
52
0
    long native;
53
0
    INTEGER_t tmpint;
54
55
0
    if(!sptr) ASN__ENCODE_FAILED;
56
57
0
    native = *(const long *)sptr;
58
59
0
    ASN_DEBUG("Encoding NativeInteger %s %ld (APER)", td->name, native);
60
61
0
    memset(&tmpint, 0, sizeof(tmpint));
62
0
    if((specs&&specs->field_unsigned)
63
0
            ? asn_ulong2INTEGER(&tmpint, (unsigned long)native)
64
0
            : asn_long2INTEGER(&tmpint, native))
65
0
        ASN__ENCODE_FAILED;
66
0
    er = INTEGER_encode_aper(td, constraints, &tmpint, po);
67
0
    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
68
0
    return er;
69
0
}