diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_bitstr.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_bitstr.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c index 0fb9ce0c2a..34179960b8 100644 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ b/src/lib/libcrypto/asn1/a_bitstr.c | |||
@@ -223,3 +223,26 @@ int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) | |||
223 | return((a->data[w]&v) != 0); | 223 | return((a->data[w]&v) != 0); |
224 | } | 224 | } |
225 | 225 | ||
226 | /* | ||
227 | * Checks if the given bit string contains only bits specified by | ||
228 | * the flags vector. Returns 0 if there is at least one bit set in 'a' | ||
229 | * which is not specified in 'flags', 1 otherwise. | ||
230 | * 'len' is the length of 'flags'. | ||
231 | */ | ||
232 | int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, | ||
233 | unsigned char *flags, int flags_len) | ||
234 | { | ||
235 | int i, ok; | ||
236 | /* Check if there is one bit set at all. */ | ||
237 | if (!a || !a->data) return 1; | ||
238 | |||
239 | /* Check each byte of the internal representation of the bit string. */ | ||
240 | ok = 1; | ||
241 | for (i = 0; i < a->length && ok; ++i) | ||
242 | { | ||
243 | unsigned char mask = i < flags_len ? ~flags[i] : 0xff; | ||
244 | /* We are done if there is an unneeded bit set. */ | ||
245 | ok = (a->data[i] & mask) == 0; | ||
246 | } | ||
247 | return ok; | ||
248 | } | ||