00001 /* 00002 * KeyUsage 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Distributed under the terms of the Botan license 00006 */ 00007 00008 #include <botan/pubkey_enums.h> 00009 #include <botan/ber_dec.h> 00010 00011 namespace Botan { 00012 00013 namespace BER { 00014 00015 /* 00016 * Decode a BER encoded KeyUsage 00017 */ 00018 void decode(BER_Decoder& source, Key_Constraints& key_usage) 00019 { 00020 BER_Object obj = source.get_next_object(); 00021 00022 if(obj.type_tag != BIT_STRING || obj.class_tag != UNIVERSAL) 00023 throw BER_Bad_Tag("Bad tag for usage constraint", 00024 obj.type_tag, obj.class_tag); 00025 if(obj.value.size() != 2 && obj.value.size() != 3) 00026 throw BER_Decoding_Error("Bad size for BITSTRING in usage constraint"); 00027 if(obj.value[0] >= 8) 00028 throw BER_Decoding_Error("Invalid unused bits in usage constraint"); 00029 00030 const byte mask = (0xFF << obj.value[0]); 00031 obj.value[obj.value.size()-1] &= mask; 00032 00033 u16bit usage = 0; 00034 for(u32bit j = 1; j != obj.value.size(); ++j) 00035 usage = (obj.value[j] << 8) | usage; 00036 00037 key_usage = Key_Constraints(usage); 00038 } 00039 00040 } 00041 00042 }
1.5.8