int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
	{
	int w,v,iv;
	unsigned char *c;

	w=n/8;
	v=1<<(7-(n&0x07));
	iv= ~v;

	a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */

	if (a == NULL) return(0);
	if ((a->length < (w+1)) || (a->data == NULL))
		{
		if (!value) return(1); /* Don't need to set */
		if (a->data == NULL)
			c=(unsigned char *)OPENSSL_malloc(w+1);
		else
			c=(unsigned char *)OPENSSL_realloc(a->data,w+1);
		if (c == NULL) return(0);
		a->data=c;
		a->length=w+1;
		c[w]=0;
		}
	a->data[w]=((a->data[w])&iv)|v;
	while ((a->length > 0) && (a->data[a->length-1] == 0))
		a->length--;
	return(1);
	}