/* Checks if the given bit string contains only bits specified by the flags vector. Returns 0 if there is at least one bit set in 'a' which is not specified in 'flags', 1 otherwise. 'len' is the length of 'flags'.  */
int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, unsigned char *flags, int flags_len)
/* Checks if the given bit string contains only bits specified by the flags vector. Returns 0 if there is at least one bit set in 'a' which is not specified in 'flags', 1 otherwise. 'len' is the length of 'flags'.  */
int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, unsigned char *flags, int flags_len)
{
    int i, ok;
    if (!a || !a->data)
        return 1;
    ok = 1;
    for (i = 0; i < a->length && ok; ++i) {
        unsigned char mask = i < flags_len ? ~flags[i] : 0xff;
        ok = (a->data[i] & mask) == 0;
    }
    return ok;
}