1f579bf8eSKris Kennaway /* t_bitst.c */ 2f579bf8eSKris Kennaway /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 3f579bf8eSKris Kennaway * project 1999. 4f579bf8eSKris Kennaway */ 5f579bf8eSKris Kennaway /* ==================================================================== 6f579bf8eSKris Kennaway * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 7f579bf8eSKris Kennaway * 8f579bf8eSKris Kennaway * Redistribution and use in source and binary forms, with or without 9f579bf8eSKris Kennaway * modification, are permitted provided that the following conditions 10f579bf8eSKris Kennaway * are met: 11f579bf8eSKris Kennaway * 12f579bf8eSKris Kennaway * 1. Redistributions of source code must retain the above copyright 13f579bf8eSKris Kennaway * notice, this list of conditions and the following disclaimer. 14f579bf8eSKris Kennaway * 15f579bf8eSKris Kennaway * 2. Redistributions in binary form must reproduce the above copyright 16f579bf8eSKris Kennaway * notice, this list of conditions and the following disclaimer in 17f579bf8eSKris Kennaway * the documentation and/or other materials provided with the 18f579bf8eSKris Kennaway * distribution. 19f579bf8eSKris Kennaway * 20f579bf8eSKris Kennaway * 3. All advertising materials mentioning features or use of this 21f579bf8eSKris Kennaway * software must display the following acknowledgment: 22f579bf8eSKris Kennaway * "This product includes software developed by the OpenSSL Project 23f579bf8eSKris Kennaway * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 24f579bf8eSKris Kennaway * 25f579bf8eSKris Kennaway * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26f579bf8eSKris Kennaway * endorse or promote products derived from this software without 27f579bf8eSKris Kennaway * prior written permission. For written permission, please contact 28f579bf8eSKris Kennaway * licensing@OpenSSL.org. 29f579bf8eSKris Kennaway * 30f579bf8eSKris Kennaway * 5. Products derived from this software may not be called "OpenSSL" 31f579bf8eSKris Kennaway * nor may "OpenSSL" appear in their names without prior written 32f579bf8eSKris Kennaway * permission of the OpenSSL Project. 33f579bf8eSKris Kennaway * 34f579bf8eSKris Kennaway * 6. Redistributions of any form whatsoever must retain the following 35f579bf8eSKris Kennaway * acknowledgment: 36f579bf8eSKris Kennaway * "This product includes software developed by the OpenSSL Project 37f579bf8eSKris Kennaway * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 38f579bf8eSKris Kennaway * 39f579bf8eSKris Kennaway * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40f579bf8eSKris Kennaway * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41f579bf8eSKris Kennaway * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42f579bf8eSKris Kennaway * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43f579bf8eSKris Kennaway * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44f579bf8eSKris Kennaway * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45f579bf8eSKris Kennaway * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46f579bf8eSKris Kennaway * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47f579bf8eSKris Kennaway * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48f579bf8eSKris Kennaway * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49f579bf8eSKris Kennaway * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50f579bf8eSKris Kennaway * OF THE POSSIBILITY OF SUCH DAMAGE. 51f579bf8eSKris Kennaway * ==================================================================== 52f579bf8eSKris Kennaway * 53f579bf8eSKris Kennaway * This product includes cryptographic software written by Eric Young 54f579bf8eSKris Kennaway * (eay@cryptsoft.com). This product includes software written by Tim 55f579bf8eSKris Kennaway * Hudson (tjh@cryptsoft.com). 56f579bf8eSKris Kennaway * 57f579bf8eSKris Kennaway */ 58f579bf8eSKris Kennaway 59f579bf8eSKris Kennaway #include <stdio.h> 60f579bf8eSKris Kennaway #include "cryptlib.h" 61f579bf8eSKris Kennaway #include <openssl/conf.h> 62f579bf8eSKris Kennaway #include <openssl/x509v3.h> 63f579bf8eSKris Kennaway 64f579bf8eSKris Kennaway int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, 65f579bf8eSKris Kennaway BIT_STRING_BITNAME *tbl, int indent) 66f579bf8eSKris Kennaway { 67f579bf8eSKris Kennaway BIT_STRING_BITNAME *bnam; 68f579bf8eSKris Kennaway char first = 1; 69f579bf8eSKris Kennaway BIO_printf(out, "%*s", indent, ""); 70f579bf8eSKris Kennaway for(bnam = tbl; bnam->lname; bnam++) { 71f579bf8eSKris Kennaway if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) { 72f579bf8eSKris Kennaway if(!first) BIO_puts(out, ", "); 73f579bf8eSKris Kennaway BIO_puts(out, bnam->lname); 74f579bf8eSKris Kennaway first = 0; 75f579bf8eSKris Kennaway } 76f579bf8eSKris Kennaway } 77f579bf8eSKris Kennaway BIO_puts(out, "\n"); 78f579bf8eSKris Kennaway return 1; 79f579bf8eSKris Kennaway } 80f579bf8eSKris Kennaway 81f579bf8eSKris Kennaway int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value, 82f579bf8eSKris Kennaway BIT_STRING_BITNAME *tbl) 83f579bf8eSKris Kennaway { 84f579bf8eSKris Kennaway int bitnum; 85f579bf8eSKris Kennaway bitnum = ASN1_BIT_STRING_num_asc(name, tbl); 86f579bf8eSKris Kennaway if(bitnum < 0) return 0; 87f579bf8eSKris Kennaway if(bs) ASN1_BIT_STRING_set_bit(bs, bitnum, value); 88f579bf8eSKris Kennaway return 1; 89f579bf8eSKris Kennaway } 90f579bf8eSKris Kennaway 91f579bf8eSKris Kennaway int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl) 92f579bf8eSKris Kennaway { 93f579bf8eSKris Kennaway BIT_STRING_BITNAME *bnam; 94f579bf8eSKris Kennaway for(bnam = tbl; bnam->lname; bnam++) { 95f579bf8eSKris Kennaway if(!strcmp(bnam->sname, name) || 96f579bf8eSKris Kennaway !strcmp(bnam->lname, name) ) return bnam->bitnum; 97f579bf8eSKris Kennaway } 98f579bf8eSKris Kennaway return -1; 99f579bf8eSKris Kennaway } 100