monotone

monotone Mtn Source Tree

Root/botan/asn1_ku.cpp

1/*************************************************
2* KeyUsage Source File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/asn1_obj.h>
7#include <botan/der_enc.h>
8#include <botan/ber_dec.h>
9#include <botan/bit_ops.h>
10
11namespace Botan {
12
13namespace BER {
14
15/*************************************************
16* Decode a BER encoded KeyUsage *
17*************************************************/
18void 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(u32bit 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}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status