Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl36/crypto/x509/v3_usernotice.c
Line
Count
Source
1
/*
2
 * Copyright 1999-2024 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <openssl/asn1t.h>
11
#include <openssl/x509v3.h>
12
#include "ext_dat.h"
13
14
ASN1_ITEM_TEMPLATE(OSSL_USER_NOTICE_SYNTAX) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_USER_NOTICE_SYNTAX, USERNOTICE)
15
21.8k
ASN1_ITEM_TEMPLATE_END(OSSL_USER_NOTICE_SYNTAX)
16
17
IMPLEMENT_ASN1_FUNCTIONS(OSSL_USER_NOTICE_SYNTAX)
18
19
static int print_notice(BIO *out, USERNOTICE *notice, int indent)
20
9.68k
{
21
9.68k
    int i;
22
9.68k
    ASN1_INTEGER *num;
23
9.68k
    char *tmp;
24
25
9.68k
    if (notice->noticeref) {
26
123
        NOTICEREF *ref;
27
123
        ref = notice->noticeref;
28
123
        if (BIO_printf(out, "%*sOrganization: %.*s\n", indent, "",
29
123
                ref->organization->length,
30
123
                ref->organization->data)
31
123
            <= 0)
32
0
            return 0;
33
123
        if (BIO_printf(out, "%*sNumber%s: ", indent, "",
34
123
                sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "")
35
123
            <= 0)
36
0
            return 0;
37
265
        for (i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
38
142
            num = sk_ASN1_INTEGER_value(ref->noticenos, i);
39
142
            if (i && BIO_puts(out, ", ") <= 0)
40
0
                return 0;
41
142
            if (num == NULL && BIO_puts(out, "(null)") <= 0)
42
0
                return 0;
43
142
            else {
44
142
                tmp = i2s_ASN1_INTEGER(NULL, num);
45
142
                if (tmp == NULL)
46
0
                    return 0;
47
142
                if (BIO_puts(out, tmp) <= 0) {
48
0
                    OPENSSL_free(tmp);
49
0
                    return 0;
50
0
                }
51
142
                OPENSSL_free(tmp);
52
142
            }
53
142
        }
54
123
        if (notice->exptext && BIO_puts(out, "\n") <= 0)
55
0
            return 0;
56
123
    }
57
9.68k
    if (notice->exptext == NULL)
58
8.57k
        return 1;
59
60
1.11k
    return BIO_printf(out, "%*sExplicit Text: %.*s", indent, "",
61
1.11k
               notice->exptext->length,
62
1.11k
               notice->exptext->data)
63
1.11k
        >= 0;
64
9.68k
}
65
66
static int i2r_USER_NOTICE_SYNTAX(X509V3_EXT_METHOD *method,
67
    OSSL_USER_NOTICE_SYNTAX *uns,
68
    BIO *out, int indent)
69
6.38k
{
70
6.38k
    int i;
71
6.38k
    USERNOTICE *unotice;
72
73
6.38k
    if (BIO_printf(out, "%*sUser Notices:\n", indent, "") <= 0)
74
0
        return 0;
75
76
16.0k
    for (i = 0; i < sk_USERNOTICE_num(uns); i++) {
77
9.68k
        unotice = sk_USERNOTICE_value(uns, i);
78
9.68k
        if (!print_notice(out, unotice, indent + 4))
79
0
            return 0;
80
9.68k
        if (BIO_puts(out, "\n\n") <= 0)
81
0
            return 0;
82
9.68k
    }
83
6.38k
    return 1;
84
6.38k
}
85
86
const X509V3_EXT_METHOD ossl_v3_user_notice = {
87
    NID_user_notice, 0,
88
    ASN1_ITEM_ref(OSSL_USER_NOTICE_SYNTAX),
89
    0, 0, 0, 0,
90
    0,
91
    0,
92
    0, 0,
93
    (X509V3_EXT_I2R)i2r_USER_NOTICE_SYNTAX,
94
    0,
95
    NULL
96
};