Botan 1.10.17
cms_dec.cpp
Go to the documentation of this file.
1/*
2* CMS Decoding
3* (C) 1999-2007 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#include <botan/cms_dec.h>
9#include <botan/ber_dec.h>
10#include <botan/asn1_int.h>
11#include <botan/oids.h>
12#include <botan/pem.h>
13
14namespace Botan {
15
16/*
17* CMS_Decoder Constructor
18*/
20 Private_Key* key) :
21 store(x509store)
22 {
23 status = GOOD;
24
25 add_key(key);
26
28 initial_read(in);
29 else
30 {
32 initial_read(ber);
33 }
34 }
35
36/*
37* Read the outermost ContentInfo
38*/
39void CMS_Decoder::initial_read(DataSource&)
40 {
41 // FIXME...
42
43 /*
44 BER_Decoder decoder(in);
45 BER_Decoder content_info = decoder.start_cons(SEQUENCE);
46
47 content_info.decode(next_type);
48
49
50 BER_Decoder content_type = BER::get_subsequence(content_info, ASN1_Tag(0));
51 data = content_type.get_remaining();
52 */
53
54 decode_layer();
55 }
56
57/*
58* Add another private key to use
59*/
61 {
62 if(!key)
63 return;
64
65#if 0
66 for(u32bit j = 0; j != keys.size(); j++)
67 if(keys[j]->key_id() == key->key_id())
68 return;
69#endif
70
71 keys.push_back(key);
72 }
73
74/*
75* Return the status information
76*/
78 {
79 return status;
80 }
81
82/*
83* Return the final data content
84*/
85std::string CMS_Decoder::get_data() const
86 {
87 if(layer_type() != DATA)
88 throw Invalid_State("CMS: Cannot retrieve data from non-DATA layer");
89
90 return std::string(reinterpret_cast<const char*>(&data[0]),
91 data.size());
92 }
93
94/*
95* Return the content type of this layer
96*/
98 {
99 if(type == OIDS::lookup("CMS.DataContent")) return DATA;
100 if(type == OIDS::lookup("CMS.EnvelopedData")) return ENVELOPED;
101 if(type == OIDS::lookup("CMS.CompressedData")) return COMPRESSED;
102 if(type == OIDS::lookup("CMS.SignedData")) return SIGNED;
103 if(type == OIDS::lookup("CMS.AuthenticatedData")) return AUTHENTICATED;
104 if(type == OIDS::lookup("CMS.DigestedData")) return DIGESTED;
105 return UNKNOWN;
106 }
107
108/*
109* Return some information about this layer
110*/
111std::string CMS_Decoder::layer_info() const
112 {
113 return info;
114 }
115
116/*
117* Return some information about this layer
118*/
119void CMS_Decoder::read_econtent(BER_Decoder& decoder)
120 {
121 BER_Decoder econtent_info = decoder.start_cons(SEQUENCE);
122 econtent_info.decode(next_type);
123
124 // FIXME
125 //BER_Decoder econtent = BER::get_subsequence(econtent_info, ASN1_Tag(0));
126 //econtent.decode(data, OCTET_STRING);
127 }
128
129}
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
Definition ber_dec.cpp:238
BER_Decoder & decode(bool &)
Definition ber_dec.cpp:344
CMS_Decoder(DataSource &, const X509_Store &, Private_Key *=0)
Definition cms_dec.cpp:19
Content_Type layer_type() const
Definition cms_dec.cpp:97
void add_key(Private_Key *)
Definition cms_dec.cpp:60
std::string get_data() const
Definition cms_dec.cpp:85
std::string layer_info() const
Definition cms_dec.cpp:111
Status layer_status() const
Definition cms_dec.cpp:77
bool maybe_BER(DataSource &source)
Definition asn1_int.cpp:55
std::string lookup(const OID &oid)
Definition oids.cpp:31
SecureVector< byte > decode_check_label(DataSource &source, const std::string &label_want)
Definition pem.cpp:42
bool matches(DataSource &source, const std::string &extra, size_t search_range)
Definition pem.cpp:116
@ SEQUENCE
Definition asn1_int.h:35
unsigned int u32bit
Definition types.h:32
Invalid_State(const std::string &err)
Definition exceptn.h:27