Commit 9f5466b9 authored by FdaSilvaYY's avatar FdaSilvaYY Committed by Richard Levitte
Browse files

Constify some X509_NAME, ASN1 printing code



 ASN1_buf_print, asn1_print_*, X509_NAME_oneline, X509_NAME_print

Reviewed-by: default avatarMatt Caswell <matt@openssl.org>
Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
parent bf9d5e48
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@ static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf,
 */

static int do_dump(unsigned long lflags, char_io *io_ch, void *arg,
                   ASN1_STRING *str)
                   const ASN1_STRING *str)
{
    /*
     * Placing the ASN1_STRING in a temp ASN1_TYPE allows the DER encoding to
@@ -296,7 +296,7 @@ static const signed char tag2nbyte[] = {
 */

static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
                       ASN1_STRING *str)
                       const ASN1_STRING *str)
{
    int outlen, len;
    int type;
@@ -388,14 +388,14 @@ static int do_indent(char_io *io_ch, void *arg, int indent)
#define FN_WIDTH_LN     25
#define FN_WIDTH_SN     10

static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
static int do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n,
                      int indent, unsigned long flags)
{
    int i, prev = -1, orflags, cnt;
    int fn_opt, fn_nid;
    ASN1_OBJECT *fn;
    ASN1_STRING *val;
    X509_NAME_ENTRY *ent;
    const ASN1_STRING *val;
    const X509_NAME_ENTRY *ent;
    char objtmp[80];
    const char *objbuf;
    int outlen, len;
@@ -455,9 +455,9 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
    cnt = X509_NAME_entry_count(n);
    for (i = 0; i < cnt; i++) {
        if (flags & XN_FLAG_DN_REV)
            ent = X509_NAME_get_entry(n, cnt - i - 1);
            ent = X509_NAME_get_entry((X509_NAME *)n, cnt - i - 1);
        else
            ent = X509_NAME_get_entry(n, i);
            ent = X509_NAME_get_entry((X509_NAME *)n, i);
        if (prev != -1) {
            if (prev == X509_NAME_ENTRY_set(ent)) {
                if (!io_ch(arg, sep_mv, sep_mv_len))
@@ -526,7 +526,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,

/* Wrappers round the main functions */

int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent,
int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent,
                       unsigned long flags)
{
    if (flags == XN_FLAG_COMPAT)
@@ -535,7 +535,7 @@ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent,
}

#ifndef OPENSSL_NO_STDIO
int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent,
int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent,
                          unsigned long flags)
{
    if (flags == XN_FLAG_COMPAT) {
@@ -552,13 +552,13 @@ int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent,
}
#endif

int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags)
{
    return do_print_ex(send_bio_chars, out, flags, str);
}

#ifndef OPENSSL_NO_STDIO
int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags)
{
    return do_print_ex(send_fp_chars, fp, flags, str);
}
+2 −2
Original line number Diff line number Diff line
@@ -389,7 +389,7 @@ static int asn1_print_boolean(BIO *out, int boolval)

}

static int asn1_print_integer(BIO *out, ASN1_INTEGER *str)
static int asn1_print_integer(BIO *out, const ASN1_INTEGER *str)
{
    char *s;
    int ret = 1;
@@ -415,7 +415,7 @@ static int asn1_print_oid(BIO *out, const ASN1_OBJECT *oid)
    return 1;
}

static int asn1_print_obstring(BIO *out, ASN1_STRING *str, int indent)
static int asn1_print_obstring(BIO *out, const ASN1_STRING *str, int indent)
{
    if (str->type == V_ASN1_BIT_STRING) {
        if (BIO_printf(out, " (%ld unused bits)\n", str->flags & 0x7) <= 0)
+2 −2
Original line number Diff line number Diff line
@@ -22,9 +22,9 @@

#define NAME_ONELINE_MAX    (1024 * 1024)

char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len)
{
    X509_NAME_ENTRY *ne;
    const X509_NAME_ENTRY *ne;
    int i;
    int n, lold, l, l1, l2, num, j, type;
    const char *s;
+9 −5
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ int X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, char *buf
                              int len)
{
    int i;
    ASN1_STRING *data;
    const ASN1_STRING *data;

    i = X509_NAME_get_index_by_OBJ(name, obj, -1);
    if (i < 0)
@@ -176,7 +176,7 @@ int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,
 * if set is -1, append to previous set, 0 'a new one', and 1, prepend to the
 * guy we are about to stomp on.
 */
int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
int X509_NAME_add_entry(X509_NAME *name, const X509_NAME_ENTRY *ne, int loc,
                        int set)
{
    X509_NAME_ENTRY *new_name = NULL;
@@ -214,7 +214,11 @@ int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
        inc = (set == 0) ? 1 : 0;
    }

    if ((new_name = X509_NAME_ENTRY_dup(ne)) == NULL)
    /*
     * X509_NAME_ENTRY_dup is ASN1 generated code, that can't be easily
     * const'ified; harmless cast as dup() don't modify its input.
     */
    if ((new_name = X509_NAME_ENTRY_dup((X509_NAME_ENTRY *)ne)) == NULL)
        goto err;
    new_name->set = set;
    if (!sk_X509_NAME_ENTRY_insert(sk, new_name, loc)) {
@@ -334,14 +338,14 @@ int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
    return (1);
}

ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne)
ASN1_OBJECT *X509_NAME_ENTRY_get_object(const X509_NAME_ENTRY *ne)
{
    if (ne == NULL)
        return (NULL);
    return (ne->object);
}

ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
ASN1_STRING *X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne)
{
    if (ne == NULL)
        return (NULL);
+2 −2
Original line number Diff line number Diff line
@@ -290,7 +290,7 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval,
                              int indent,
                              const char *fname, const ASN1_PCTX *pctx)
{
    if (X509_NAME_print_ex(out, (X509_NAME *)*pval,
    if (X509_NAME_print_ex(out, (const X509_NAME *)*pval,
                           indent, pctx->nm_flags) <= 0)
        return 0;
    return 2;
@@ -494,7 +494,7 @@ int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
    return (*xn != NULL);
}

int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase)
{
    char *s, *c, *b;
    int l, i;
Loading