Botan  1.10.9
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

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