blob: 1fa236d9ff07877c711752e041744e1f555e2ac9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/*************************************************
* KeyUsage Source File *
* (C) 1999-2007 The Botan Project *
*************************************************/
#include <botan/asn1_obj.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/bit_ops.h>
namespace Botan {
namespace BER {
/*************************************************
* Decode a BER encoded KeyUsage *
*************************************************/
void decode(BER_Decoder& source, Key_Constraints& key_usage)
{
BER_Object obj = source.get_next_object();
if(obj.type_tag != BIT_STRING || obj.class_tag != UNIVERSAL)
throw BER_Bad_Tag("Bad tag for usage constraint",
obj.type_tag, obj.class_tag);
if(obj.value.size() != 2 && obj.value.size() != 3)
throw BER_Decoding_Error("Bad size for BITSTRING in usage constraint");
if(obj.value[0] >= 8)
throw BER_Decoding_Error("Invalid unused bits in usage constraint");
const byte mask = (0xFF << obj.value[0]);
obj.value[obj.value.size()-1] &= mask;
u16bit usage = 0;
for(u32bit j = 1; j != obj.value.size(); ++j)
usage = (obj.value[j] << 8) | usage;
key_usage = Key_Constraints(usage);
}
}
}
|