diff options
author | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
commit | a2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch) | |
tree | ad3d6c4fcc8dd0f403f8105598943616246fe172 /src/asn1_int.cpp |
Initial checkin1.5.6
Diffstat (limited to 'src/asn1_int.cpp')
-rw-r--r-- | src/asn1_int.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/asn1_int.cpp b/src/asn1_int.cpp new file mode 100644 index 000000000..324187eff --- /dev/null +++ b/src/asn1_int.cpp @@ -0,0 +1,56 @@ +/************************************************* +* ASN.1 Internals Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/asn1_int.h> +#include <botan/der_enc.h> +#include <botan/data_src.h> +#include <botan/parsing.h> + +namespace Botan { + +/************************************************* +* BER Decoding Exceptions * +*************************************************/ +BER_Decoding_Error::BER_Decoding_Error(const std::string& str) : + Decoding_Error("BER: " + str) {} + +BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag) : + BER_Decoding_Error(str + ": " + to_string(tag)) {} + +BER_Bad_Tag::BER_Bad_Tag(const std::string& str, + ASN1_Tag tag1, ASN1_Tag tag2) : + BER_Decoding_Error(str + ": " + to_string(tag1) + "/" + to_string(tag2)) {} + +namespace ASN1 { + +/************************************************* +* Put some arbitrary bytes into a SEQUENCE * +*************************************************/ +SecureVector<byte> put_in_sequence(const MemoryRegion<byte>& contents) + { + DER_Encoder encoder; + encoder.start_sequence(); + encoder.add_raw_octets(contents); + encoder.end_sequence(); + return encoder.get_contents(); + } + +/************************************************* +* Do heuristic tests for BER data * +*************************************************/ +bool maybe_BER(DataSource& source) + { + byte first_byte; + if(!source.peek_byte(first_byte)) + throw Stream_IO_Error("ASN1::maybe_BER: Source was empty"); + + if(first_byte == (SEQUENCE | CONSTRUCTED)) + return true; + return false; + } + +} + +} |