monotone

monotone Mtn Source Tree

Root/botan/asn1_int.cpp

1/*************************************************
2* ASN.1 Internals Source File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/asn1_int.h>
7#include <botan/der_enc.h>
8#include <botan/ber_dec.h>
9#include <botan/data_src.h>
10#include <botan/parsing.h>
11
12namespace Botan {
13
14/*************************************************
15* BER Decoding Exceptions *
16*************************************************/
17BER_Decoding_Error::BER_Decoding_Error(const std::string& str) :
18 Decoding_Error("BER: " + str) {}
19
20BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag) :
21 BER_Decoding_Error(str + ": " + to_string(tag)) {}
22
23BER_Bad_Tag::BER_Bad_Tag(const std::string& str,
24 ASN1_Tag tag1, ASN1_Tag tag2) :
25 BER_Decoding_Error(str + ": " + to_string(tag1) + "/" + to_string(tag2)) {}
26
27namespace ASN1 {
28
29/*************************************************
30* Put some arbitrary bytes into a SEQUENCE *
31*************************************************/
32SecureVector<byte> put_in_sequence(const MemoryRegion<byte>& contents)
33 {
34 return DER_Encoder()
35 .start_cons(SEQUENCE)
36 .raw_bytes(contents)
37 .end_cons()
38 .get_contents();
39 }
40
41/*************************************************
42* Convert a BER object into a string object *
43*************************************************/
44std::string to_string(const BER_Object& obj)
45 {
46 std::string str((const char*)obj.value.begin(), obj.value.size());
47 return str;
48 }
49
50/*************************************************
51* Do heuristic tests for BER data *
52*************************************************/
53bool maybe_BER(DataSource& source)
54 {
55 byte first_byte;
56 if(!source.peek_byte(first_byte))
57 throw Stream_IO_Error("ASN1::maybe_BER: Source was empty");
58
59 if(first_byte == (SEQUENCE | CONSTRUCTED))
60 return true;
61 return false;
62 }
63
64}
65
66}

Archive Download this file

Branches

Tags

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