monotone

monotone Mtn Source Tree

Root/botan/get_pbe.cpp

1/*************************************************
2* PBE Retrieval Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/oids.h>
7#include <botan/lookup.h>
8#include <botan/pbe_pkcs.h>
9#include <botan/parsing.h>
10
11namespace Botan {
12
13/*************************************************
14* Get an encryption PBE, set new parameters *
15*************************************************/
16PBE* get_pbe(const std::string& pbe_name)
17 {
18 std::vector<std::string> algo_name;
19 algo_name = parse_algorithm_name(pbe_name);
20
21 if(algo_name.size() != 3)
22 throw Invalid_Algorithm_Name(pbe_name);
23
24 const std::string pbe = algo_name[0];
25 const std::string digest = algo_name[1];
26 const std::string cipher = algo_name[2];
27
28 PBE* pbe_obj = 0;
29
30 if(pbe == "PBE-PKCS5v15")
31 pbe_obj = new PBE_PKCS5v15(digest, cipher, ENCRYPTION);
32 else if(pbe == "PBE-PKCS5v20")
33 pbe_obj = new PBE_PKCS5v20(digest, cipher);
34
35 if(!pbe_obj)
36 throw Algorithm_Not_Found(pbe_name);
37
38 pbe_obj->new_params();
39
40 return pbe_obj;
41 }
42
43/*************************************************
44* Get a decryption PBE, decode parameters *
45*************************************************/
46PBE* get_pbe(const OID& pbe_oid, DataSource& params)
47 {
48 std::vector<std::string> algo_name;
49 algo_name = parse_algorithm_name(OIDS::lookup(pbe_oid));
50
51 if(algo_name.size() < 1)
52 throw Invalid_Algorithm_Name(pbe_oid.as_string());
53 const std::string pbe_algo = algo_name[0];
54
55 if(pbe_algo == "PBE-PKCS5v15")
56 {
57 if(algo_name.size() != 3)
58 throw Invalid_Algorithm_Name(pbe_oid.as_string());
59 const std::string digest = algo_name[1];
60 const std::string cipher = algo_name[2];
61 PBE* pbe = new PBE_PKCS5v15(digest, cipher, DECRYPTION);
62 pbe->decode_params(params);
63 return pbe;
64 }
65 else if(pbe_algo == "PBE-PKCS5v20")
66 return new PBE_PKCS5v20(params);
67
68 throw Algorithm_Not_Found(pbe_oid.as_string());
69 }
70
71}

Archive Download this file

Branches

Tags

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