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