Botan: src/pubkey/pubkey_enums.cpp Source File

Botan 1.10.17

pubkey_enums.cpp
Go to the documentation of this file.
1 /*
2 * KeyUsage
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/pubkey_enums.h>
9 #include <botan/ber_dec.h>
10
11 namespace Botan {
12
13 namespace BER {
14
15 /*
16 * Decode a BER encoded KeyUsage
17 */
18 void decode(BER_Decoder& source, Key_Constraints& key_usage)
19 {
20 BER_Object obj = source.get_next_object();
21
22 if(obj.type_tag != BIT_STRING || obj.class_tag != UNIVERSAL)
23 throw BER_Bad_Tag("Bad tag for usage constraint",
24 obj.type_tag, obj.class_tag);
25 if(obj.value.size() != 2 && obj.value.size() != 3)
26 throw BER_Decoding_Error("Bad size for BITSTRING in usage constraint");
27 if(obj.value[0] >= 8)
28 throw BER_Decoding_Error("Invalid unused bits in usage constraint");
29
30 const byte mask = (0xFF << obj.value[0]);
31 obj.value[obj.value.size()-1] &= mask;
32
33 u16bit usage = 0;
34 for(size_t j = 1; j != obj.value.size(); ++j)
35 usage = (obj.value[j] << 8) | usage;
36
37 key_usage = Key_Constraints(usage);
38 }
39
40 }
41
42 }
Botan::UNIVERSAL
Definition: asn1_int.h:20
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::BER::decode
void decode(BER_Decoder &source, Key_Constraints &key_usage)
Definition: pubkey_enums.cpp:18
Botan::u16bit
unsigned short u16bit
Definition: types.h:27
Botan
Definition: algo_base.h:14
Botan::BER_Object::value
SecureVector< byte > value
Definition: asn1_int.h:83
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:196
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::BER_Object::class_tag
ASN1_Tag class_tag
Definition: asn1_int.h:82
Botan::BER_Object::type_tag
ASN1_Tag type_tag
Definition: asn1_int.h:82
Botan::BIT_STRING
Definition: asn1_int.h:30
Botan::BER_Decoding_Error
Definition: asn1_int.h:107
Botan::BER_Decoder
Definition: ber_dec.h:19
Botan::BER_Object
Definition: asn1_int.h:77
Botan::BER_Bad_Tag
Definition: asn1_int.h:115
Botan::Key_Constraints
Key_Constraints
Definition: pubkey_enums.h:18