159191Skris/* t_bitst.c */
2194206Ssimon/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
359191Skris * project 1999.
459191Skris */
559191Skris/* ====================================================================
659191Skris * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
759191Skris *
859191Skris * Redistribution and use in source and binary forms, with or without
959191Skris * modification, are permitted provided that the following conditions
1059191Skris * are met:
1159191Skris *
1259191Skris * 1. Redistributions of source code must retain the above copyright
1359191Skris *    notice, this list of conditions and the following disclaimer.
1459191Skris *
1559191Skris * 2. Redistributions in binary form must reproduce the above copyright
1659191Skris *    notice, this list of conditions and the following disclaimer in
1759191Skris *    the documentation and/or other materials provided with the
1859191Skris *    distribution.
1959191Skris *
2059191Skris * 3. All advertising materials mentioning features or use of this
2159191Skris *    software must display the following acknowledgment:
2259191Skris *    "This product includes software developed by the OpenSSL Project
2359191Skris *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
2459191Skris *
2559191Skris * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2659191Skris *    endorse or promote products derived from this software without
2759191Skris *    prior written permission. For written permission, please contact
2859191Skris *    licensing@OpenSSL.org.
2959191Skris *
3059191Skris * 5. Products derived from this software may not be called "OpenSSL"
3159191Skris *    nor may "OpenSSL" appear in their names without prior written
3259191Skris *    permission of the OpenSSL Project.
3359191Skris *
3459191Skris * 6. Redistributions of any form whatsoever must retain the following
3559191Skris *    acknowledgment:
3659191Skris *    "This product includes software developed by the OpenSSL Project
3759191Skris *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
3859191Skris *
3959191Skris * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
4059191Skris * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4159191Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4259191Skris * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
4359191Skris * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4459191Skris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4559191Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4659191Skris * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4759191Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4859191Skris * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4959191Skris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
5059191Skris * OF THE POSSIBILITY OF SUCH DAMAGE.
5159191Skris * ====================================================================
5259191Skris *
5359191Skris * This product includes cryptographic software written by Eric Young
5459191Skris * (eay@cryptsoft.com).  This product includes software written by Tim
5559191Skris * Hudson (tjh@cryptsoft.com).
5659191Skris *
5759191Skris */
5859191Skris
5959191Skris#include <stdio.h>
6059191Skris#include "cryptlib.h"
6159191Skris#include <openssl/conf.h>
6259191Skris#include <openssl/x509v3.h>
6359191Skris
6459191Skrisint ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
6559191Skris				BIT_STRING_BITNAME *tbl, int indent)
6659191Skris{
6759191Skris	BIT_STRING_BITNAME *bnam;
6859191Skris	char first = 1;
6959191Skris	BIO_printf(out, "%*s", indent, "");
7059191Skris	for(bnam = tbl; bnam->lname; bnam++) {
7159191Skris		if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
7259191Skris			if(!first) BIO_puts(out, ", ");
7359191Skris			BIO_puts(out, bnam->lname);
7459191Skris			first = 0;
7559191Skris		}
7659191Skris	}
7759191Skris	BIO_puts(out, "\n");
7859191Skris	return 1;
7959191Skris}
8059191Skris
8159191Skrisint ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
8259191Skris				BIT_STRING_BITNAME *tbl)
8359191Skris{
8459191Skris	int bitnum;
8559191Skris	bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
8659191Skris	if(bitnum < 0) return 0;
87160814Ssimon	if(bs) {
88160814Ssimon		if(!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
89160814Ssimon			return 0;
90160814Ssimon	}
9159191Skris	return 1;
9259191Skris}
9359191Skris
9459191Skrisint ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
9559191Skris{
9659191Skris	BIT_STRING_BITNAME *bnam;
9759191Skris	for(bnam = tbl; bnam->lname; bnam++) {
9859191Skris		if(!strcmp(bnam->sname, name) ||
9959191Skris			!strcmp(bnam->lname, name) ) return bnam->bitnum;
10059191Skris	}
10159191Skris	return -1;
10259191Skris}
103