aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/pubkey_enums.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-07-15 15:12:20 +0000
committerlloyd <[email protected]>2009-07-15 15:12:20 +0000
commit6fd01228840942ad122d1adabb3f7971a4e3b244 (patch)
tree57df224bd849d325e9747a374c85784abdd0e76c /src/pubkey/pubkey_enums.cpp
parent11470400cd77cbd20f60247f0a07fcac45772646 (diff)
Move the contents of pubkey/pubkey (which was kind of a catch-all to
just toplevel pubkey). This was a convention I realized made sense sometime on when I was first doing the modularization changes. Move pkcs8.* and x509_key.* to pk_codecs
Diffstat (limited to 'src/pubkey/pubkey_enums.cpp')
-rw-r--r--src/pubkey/pubkey_enums.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/pubkey/pubkey_enums.cpp b/src/pubkey/pubkey_enums.cpp
new file mode 100644
index 000000000..327107dd1
--- /dev/null
+++ b/src/pubkey/pubkey_enums.cpp
@@ -0,0 +1,42 @@
+/*
+* KeyUsage
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/pubkey_enums.h>
+#include <botan/ber_dec.h>
+
+namespace Botan {
+
+namespace BER {
+
+/*
+* Decode a BER encoded KeyUsage
+*/
+void decode(BER_Decoder& source, Key_Constraints& key_usage)
+ {
+ 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(u32bit j = 1; j != obj.value.size(); ++j)
+ usage = (obj.value[j] << 8) | usage;
+
+ key_usage = Key_Constraints(usage);
+ }
+
+}
+
+}