Botan  1.11.15
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 19 of file key_constraint.cpp.

References Botan::BIT_STRING, Botan::BER_Object::class_tag, Botan::BER_Decoder::get_next_object(), Botan::BER_Object::type_tag, Botan::UNIVERSAL, and Botan::BER_Object::value.

Referenced by Botan::OCSP::CertID::CertID(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::BigInt::decode(), Botan::BER_Decoder::decode_and_check(), Botan::BER_Decoder::decode_optional_string(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and Botan::SRP6_Authenticator_File::SRP6_Authenticator_File().

   {
   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(size_t j = 1; j != obj.value.size(); ++j)
      usage = (obj.value[j] << 8) | usage;

   key_usage = Key_Constraints(usage);
   }