aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-06-05 16:43:58 +0000
committerlloyd <[email protected]>2012-06-05 16:43:58 +0000
commit4d1378782d83fda342afc3e200f38ef6964ae6e2 (patch)
tree873e7742441cfd3e7701b211429277635811eb90
parentb90c6b3654ff1bff53632f4083ae440d8bd9fd99 (diff)
Modify DL_Group::PEM_decode and BER_decode to take values instead of
DataSource&. Remove spurious DataSource_Memory from ec_group.cpp Some indent fixes
-rw-r--r--src/codec/pem/pem.h4
-rw-r--r--src/pubkey/dl_algo/dl_algo.cpp6
-rw-r--r--src/pubkey/dl_group/dl_group.cpp15
-rw-r--r--src/pubkey/dl_group/dl_group.h9
-rw-r--r--src/pubkey/ec_group/ec_group.cpp4
-rw-r--r--src/pubkey/pkcs8.cpp2
6 files changed, 19 insertions, 21 deletions
diff --git a/src/codec/pem/pem.h b/src/codec/pem/pem.h
index 6c33c642d..24da1448a 100644
--- a/src/codec/pem/pem.h
+++ b/src/codec/pem/pem.h
@@ -47,14 +47,14 @@ inline std::string encode(const secure_vector<byte>& data,
* @param label is set to the PEM label found for later inspection
*/
BOTAN_DLL secure_vector<byte> decode(DataSource& pem,
- std::string& label);
+ std::string& label);
/**
* Decode PEM data
* @param label is set to the PEM label found for later inspection
*/
BOTAN_DLL secure_vector<byte> decode(const std::string& pem,
- std::string& label);
+ std::string& label);
/**
* Decode PEM data
diff --git a/src/pubkey/dl_algo/dl_algo.cpp b/src/pubkey/dl_algo/dl_algo.cpp
index 1034a3252..c90e7651e 100644
--- a/src/pubkey/dl_algo/dl_algo.cpp
+++ b/src/pubkey/dl_algo/dl_algo.cpp
@@ -27,8 +27,7 @@ DL_Scheme_PublicKey::DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits,
DL_Group::Format format)
{
- DataSource_Memory source(alg_id.parameters);
- group.BER_decode(source, format);
+ group.BER_decode(alg_id.parameters, format);
BER_Decoder(key_bits).decode(y);
}
@@ -42,8 +41,7 @@ DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits,
DL_Group::Format format)
{
- DataSource_Memory source(alg_id.parameters);
- group.BER_decode(source, format);
+ group.BER_decode(alg_id.parameters, format);
BER_Decoder(key_bits).decode(x);
}
diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp
index 93bbcbb2d..cf89abc8d 100644
--- a/src/pubkey/dl_group/dl_group.cpp
+++ b/src/pubkey/dl_group/dl_group.cpp
@@ -31,13 +31,12 @@ DL_Group::DL_Group()
*/
DL_Group::DL_Group(const std::string& type)
{
- std::string grp_contents = global_state().get("dl", type);
+ const std::string grp_contents = global_state().get("dl", type);
if(grp_contents == "")
throw Invalid_Argument("DL_Group: Unknown group " + type);
- DataSource_Memory pem(grp_contents);
- PEM_decode(pem);
+ PEM_decode(grp_contents);
}
/*
@@ -263,11 +262,12 @@ std::string DL_Group::PEM_encode(Format format) const
/*
* Decode BER encoded parameters
*/
-void DL_Group::BER_decode(DataSource& source, Format format)
+void DL_Group::BER_decode(const std::vector<byte>& data,
+ Format format)
{
BigInt new_p, new_q, new_g;
- BER_Decoder decoder(source);
+ BER_Decoder decoder(data);
BER_Decoder ber = decoder.start_cons(SEQUENCE);
if(format == ANSI_X9_57)
@@ -299,10 +299,11 @@ void DL_Group::BER_decode(DataSource& source, Format format)
/*
* Decode PEM encoded parameters
*/
-void DL_Group::PEM_decode(DataSource& source)
+void DL_Group::PEM_decode(const std::string& pem)
{
std::string label;
- DataSource_Memory ber(PEM_Code::decode(source, label));
+
+ auto ber = unlock(PEM_Code::decode(pem, label));
if(label == "DH PARAMETERS")
BER_decode(ber, PKCS_3);
diff --git a/src/pubkey/dl_group/dl_group.h b/src/pubkey/dl_group/dl_group.h
index aa90388ae..fdb5efac5 100644
--- a/src/pubkey/dl_group/dl_group.h
+++ b/src/pubkey/dl_group/dl_group.h
@@ -81,16 +81,17 @@ class BOTAN_DLL DL_Group
/**
* Decode a DER/BER encoded group into this instance.
- * @param src a DataSource providing the encoded group
+ * @param ber a vector containing the DER/BER encoded group
* @param format the format of the encoded group
*/
- void BER_decode(DataSource& src, Format format);
+ void BER_decode(const std::vector<byte>& ber,
+ Format format);
/**
* Decode a PEM encoded group into this instance.
- * @param src a DataSource providing the encoded group
+ * @param pem the PEM encoding of the group
*/
- void PEM_decode(DataSource& src);
+ void PEM_decode(const std::string& pem);
/**
* Construct a DL group with uninitialized internal value.
diff --git a/src/pubkey/ec_group/ec_group.cpp b/src/pubkey/ec_group/ec_group.cpp
index 88c4616a4..9620122de 100644
--- a/src/pubkey/ec_group/ec_group.cpp
+++ b/src/pubkey/ec_group/ec_group.cpp
@@ -35,10 +35,8 @@ EC_Group::EC_Group(const std::string& str)
try
{
- DataSource_Memory input(str);
-
std::vector<byte> ber =
- unlock(PEM_Code::decode_check_label(input, "EC PARAMETERS"));
+ unlock(PEM_Code::decode_check_label(str, "EC PARAMETERS"));
*this = EC_Group(ber);
}
diff --git a/src/pubkey/pkcs8.cpp b/src/pubkey/pkcs8.cpp
index 23c021fdb..d9b92dc23 100644
--- a/src/pubkey/pkcs8.cpp
+++ b/src/pubkey/pkcs8.cpp
@@ -25,7 +25,7 @@ namespace {
* Get info from an EncryptedPrivateKeyInfo
*/
secure_vector<byte> PKCS8_extract(DataSource& source,
- AlgorithmIdentifier& pbe_alg_id)
+ AlgorithmIdentifier& pbe_alg_id)
{
secure_vector<byte> key_data;