diff options
author | lloyd <[email protected]> | 2008-09-28 20:58:26 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 20:58:26 +0000 |
commit | 3948d38e2bef3f42169f96a17cc5daa6e03fb575 (patch) | |
tree | 1fe40baedc9e49a5d734b100790f79ac70839513 /src/cms/cms_dec.cpp | |
parent | f5ebea8d593d2f6d5b536ddb978f44d80d4e873f (diff) |
Move CMS code into main src tree, though it currently doesn't compile (needs further updating)
Diffstat (limited to 'src/cms/cms_dec.cpp')
-rw-r--r-- | src/cms/cms_dec.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/src/cms/cms_dec.cpp b/src/cms/cms_dec.cpp new file mode 100644 index 000000000..edd1cd489 --- /dev/null +++ b/src/cms/cms_dec.cpp @@ -0,0 +1,123 @@ +/************************************************* +* CMS Decoding Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/cms_dec.h> +#include <botan/ber_dec.h> +#include <botan/asn1_int.h> +#include <botan/oids.h> +#include <botan/pem.h> + +namespace Botan { + +/************************************************* +* CMS_Decoder Constructor * +*************************************************/ +CMS_Decoder::CMS_Decoder(DataSource& in, const X509_Store& x509store, + User_Interface& ui_ref, PKCS8_PrivateKey* key) : + ui(ui_ref), store(x509store) + { + status = GOOD; + + add_key(key); + + if(ASN1::maybe_BER(in) && !PEM_Code::matches(in)) + initial_read(in); + else + { + DataSource_Memory ber(PEM_Code::decode_check_label(in, "PKCS7")); + initial_read(ber); + } + } + +/************************************************* +* Read the outermost ContentInfo * +*************************************************/ +void CMS_Decoder::initial_read(DataSource& in) + { + // FIXME... + + /* + BER_Decoder decoder(in); + BER_Decoder content_info = decoder.start_cons(SEQUENCE); + + content_info.decode(next_type); + + + BER_Decoder content_type = BER::get_subsequence(content_info, ASN1_Tag(0)); + data = content_type.get_remaining(); + */ + + decode_layer(); + } + +/************************************************* +* Add another private key to use * +*************************************************/ +void CMS_Decoder::add_key(PKCS8_PrivateKey* key) + { + if(!key) + return; + + for(u32bit j = 0; j != keys.size(); j++) + if(keys[j]->key_id() == key->key_id()) + return; + + keys.push_back(key); + } + +/************************************************* +* Return the status information * +*************************************************/ +CMS_Decoder::Status CMS_Decoder::layer_status() const + { + return status; + } + +/************************************************* +* Return the final data content * +*************************************************/ +std::string CMS_Decoder::get_data() const + { + if(layer_type() != DATA) + throw Invalid_State("CMS: Cannot retrieve data from non-DATA layer"); + return std::string((const char*)data.begin(), data.size()); + } + +/************************************************* +* Return the content type of this layer * +*************************************************/ +CMS_Decoder::Content_Type CMS_Decoder::layer_type() const + { + if(type == OIDS::lookup("CMS.DataContent")) return DATA; + if(type == OIDS::lookup("CMS.EnvelopedData")) return ENVELOPED; + if(type == OIDS::lookup("CMS.CompressedData")) return COMPRESSED; + if(type == OIDS::lookup("CMS.SignedData")) return SIGNED; + if(type == OIDS::lookup("CMS.AuthenticatedData")) return AUTHENTICATED; + if(type == OIDS::lookup("CMS.DigestedData")) return DIGESTED; + return UNKNOWN; + } + +/************************************************* +* Return some information about this layer * +*************************************************/ +std::string CMS_Decoder::layer_info() const + { + return info; + } + +/************************************************* +* Return some information about this layer * +*************************************************/ +void CMS_Decoder::read_econtent(BER_Decoder& decoder) + { + BER_Decoder econtent_info = decoder.start_cons(SEQUENCE); + econtent_info.decode(next_type); + + // FIXME + //BER_Decoder econtent = BER::get_subsequence(econtent_info, ASN1_Tag(0)); + //econtent.decode(data, OCTET_STRING); + } + +} |