Botan 1.10.17

Functions
Botan::BER Namespace Reference

## Functions
void | decode (BER_Decoder &source, Key_Constraints &key_usage)

## Detailed Description

BER Decoding Function for key constraints

## Function Documentation

## ◆ decode()

void BOTAN_DLL Botan::BER::decode | ( | BER_Decoder & | source,
|  | Key_Constraints & | key_usage
| ) |  |

Definition at line 18 of file pubkey_enums.cpp.

References Botan::BIT_STRING, Botan::BER_Object::class_tag, Botan::BER_Decoder::get_next_object(), Botan::MemoryRegion< T >::size(), Botan::BER_Object::type_tag, Botan::UNIVERSAL, and Botan::BER_Object::value.

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 }
Botan::UNIVERSAL
Definition: asn1_int.h:20
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::u16bit
unsigned short u16bit
Definition: types.h:27
Botan::BIT_STRING
Definition: asn1_int.h:30
Botan::Key_Constraints
Key_Constraints
Definition: pubkey_enums.h:18