aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-27 12:02:53 +0000
committerlloyd <[email protected]>2012-05-27 12:02:53 +0000
commit4738d02a99eb371b5a22fd5547a4b63dfa77fb95 (patch)
treeb18df32bed391b0a74147ace3a162d4c3f5c6cc5 /doc/examples
parentb4bdefd0ebcf57d686a383d7460f0ade9fb9883b (diff)
Remove the PRIVATE ASN.1 tag. Not being used outside of the pretty
printer example, and really is just CONSTRUCTED | CONTEXT_SPECIFIC. Extend the ASN.1 printer to recurse into OCTET STRINGS that contain DER, and to print enumeration values. BOTAN_DLL export some OID operators (+, !=, <) Add an OID entry for 1.3.6.1.5.5.7.48.1.1 OCSP basic response. Correct the Certificate_Policies code, it was dumping policy OIDs into the extended key usage!
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/asn1.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/doc/examples/asn1.cpp b/doc/examples/asn1.cpp
index d12ee1eec..aecb688f0 100644
--- a/doc/examples/asn1.cpp
+++ b/doc/examples/asn1.cpp
@@ -5,6 +5,7 @@
#include <botan/asn1_obj.h>
#include <botan/oids.h>
#include <botan/pem.h>
+#include <botan/hex.h>
#include <botan/charset.h>
using namespace Botan;
@@ -73,7 +74,7 @@ void decode(BER_Decoder& decoder, size_t level)
that we've gotten the type info */
DER_Encoder encoder;
encoder.add_object(type_tag, class_tag, obj.value);
- secure_vector<byte> bits = encoder.get_contents();
+ std::vector<byte> bits = encoder.get_contents_unlocked();
BER_Decoder data(bits);
@@ -94,8 +95,7 @@ void decode(BER_Decoder& decoder, size_t level)
{
std::string name;
- if((class_tag & APPLICATION) || (class_tag & CONTEXT_SPECIFIC) ||
- (class_tag & PRIVATE))
+ if((class_tag & APPLICATION) || (class_tag & CONTEXT_SPECIFIC))
{
name = "cons [" + std::to_string(type_tag) + "]";
@@ -103,8 +103,6 @@ void decode(BER_Decoder& decoder, size_t level)
name += " appl";
if(class_tag & CONTEXT_SPECIFIC)
name += " context";
- if(class_tag & PRIVATE)
- name += " private";
}
else
name = type_name(type_tag) + " (cons)";
@@ -113,8 +111,7 @@ void decode(BER_Decoder& decoder, size_t level)
decode(cons_info, level+1);
}
}
- else if(class_tag == APPLICATION || class_tag == CONTEXT_SPECIFIC ||
- class_tag == PRIVATE)
+ else if((class_tag & APPLICATION) || (class_tag & CONTEXT_SPECIFIC))
{
bool not_text = false;
@@ -123,7 +120,7 @@ void decode(BER_Decoder& decoder, size_t level)
not_text = true;
Pipe pipe(((not_text) ? new Hex_Encoder : 0));
- pipe.process_msg(bits);
+ pipe.process_msg(obj.value);
emit("[" + std::to_string(type_tag) + "]", level, length,
pipe.read_all_as_string());
}
@@ -138,10 +135,14 @@ void decode(BER_Decoder& decoder, size_t level)
emit(type_name(type_tag), level, length, out);
}
- else if(type_tag == INTEGER)
+ else if(type_tag == INTEGER || type_tag == ENUMERATED)
{
BigInt number;
- data.decode(number);
+
+ if(type_tag == INTEGER)
+ data.decode(number);
+ else if(type_tag == ENUMERATED)
+ data.decode(number, ENUMERATED, class_tag);
std::vector<byte> rep;
@@ -170,7 +171,7 @@ void decode(BER_Decoder& decoder, size_t level)
}
else if(type_tag == OCTET_STRING)
{
- secure_vector<byte> bits;
+ std::vector<byte> bits;
data.decode(bits, type_tag);
bool not_text = false;
@@ -180,11 +181,20 @@ void decode(BER_Decoder& decoder, size_t level)
Pipe pipe(((not_text) ? new Hex_Encoder : 0));
pipe.process_msg(bits);
- emit(type_name(type_tag), level, length, pipe.read_all_as_string());
+
+ try
+ {
+ BER_Decoder inner(bits);
+ decode(inner, level + 1);
+ }
+ catch(...)
+ {
+ emit(type_name(type_tag), level, length, pipe.read_all_as_string());
+ }
}
else if(type_tag == BIT_STRING)
{
- secure_vector<byte> bits;
+ std::vector<byte> bits;
data.decode(bits, type_tag);
std::vector<bool> bit_set;
@@ -280,6 +290,7 @@ std::string type_name(ASN1_Tag type)
if(type == OCTET_STRING) return "OCTET STRING";
if(type == BIT_STRING) return "BIT STRING";
+ if(type == ENUMERATED) return "ENUMERATED";
if(type == INTEGER) return "INTEGER";
if(type == NULL_TAG) return "NULL";
if(type == OBJECT_ID) return "OBJECT";