Blame crypto/asn1/t_bitst.c

Packit Service 084de1
/*
Packit Service 084de1
 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
Packit Service 084de1
 *
Packit Service 084de1
 * Licensed under the OpenSSL license (the "License").  You may not use
Packit Service 084de1
 * this file except in compliance with the License.  You can obtain a copy
Packit Service 084de1
 * in the file LICENSE in the source distribution or at
Packit Service 084de1
 * https://www.openssl.org/source/license.html
Packit Service 084de1
 */
Packit Service 084de1
Packit Service 084de1
#include <stdio.h>
Packit Service 084de1
#include "internal/cryptlib.h"
Packit Service 084de1
#include <openssl/conf.h>
Packit Service 084de1
#include <openssl/x509v3.h>
Packit Service 084de1
Packit Service 084de1
int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
Packit Service 084de1
                               BIT_STRING_BITNAME *tbl, int indent)
Packit Service 084de1
{
Packit Service 084de1
    BIT_STRING_BITNAME *bnam;
Packit Service 084de1
    char first = 1;
Packit Service 084de1
    BIO_printf(out, "%*s", indent, "");
Packit Service 084de1
    for (bnam = tbl; bnam->lname; bnam++) {
Packit Service 084de1
        if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
Packit Service 084de1
            if (!first)
Packit Service 084de1
                BIO_puts(out, ", ");
Packit Service 084de1
            BIO_puts(out, bnam->lname);
Packit Service 084de1
            first = 0;
Packit Service 084de1
        }
Packit Service 084de1
    }
Packit Service 084de1
    BIO_puts(out, "\n");
Packit Service 084de1
    return 1;
Packit Service 084de1
}
Packit Service 084de1
Packit Service 084de1
int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
Packit Service 084de1
                            BIT_STRING_BITNAME *tbl)
Packit Service 084de1
{
Packit Service 084de1
    int bitnum;
Packit Service 084de1
    bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
Packit Service 084de1
    if (bitnum < 0)
Packit Service 084de1
        return 0;
Packit Service 084de1
    if (bs) {
Packit Service 084de1
        if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
Packit Service 084de1
            return 0;
Packit Service 084de1
    }
Packit Service 084de1
    return 1;
Packit Service 084de1
}
Packit Service 084de1
Packit Service 084de1
int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl)
Packit Service 084de1
{
Packit Service 084de1
    BIT_STRING_BITNAME *bnam;
Packit Service 084de1
    for (bnam = tbl; bnam->lname; bnam++) {
Packit Service 084de1
        if ((strcmp(bnam->sname, name) == 0)
Packit Service 084de1
            || (strcmp(bnam->lname, name) == 0))
Packit Service 084de1
            return bnam->bitnum;
Packit Service 084de1
    }
Packit Service 084de1
    return -1;
Packit Service 084de1
}