Commit 368d9c1f authored by ck's avatar ck
Browse files

Botan: Introduce wrapper class for shared pointers.

This allows us to quickly switch between std::tr1::shared_ptr and
QSharedPointer. The latter is the default now because of problems
with shared_ptr in certain compilers.

Reviewed-by: Bill King
parent ca7f4907
......@@ -36,7 +36,7 @@
#define BOTAN_USE_GCC_INLINE_ASM 0
#endif
#define BOTAN_USE_QT_SHARED_POINTER
#define BOTAN_USE_STD_TR1
/* Module definitions */
......
......@@ -44,6 +44,8 @@
#define BOTAN_TARGET_OS_IS_WINDOWS
#define BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK
#define BOTAN_USE_QT_SHARED_POINTER
/* Module definitions */
#if defined(Q_CC_MINGW)
# define BOTAN_USE_STD_TR1
......
......@@ -57,7 +57,7 @@ class BOTAN_DLL CurveGFp
* @param mod a shared pointer to a GFpModulus object suitable for
* *this.
*/
void set_shrd_mod(const std::tr1::shared_ptr<GFpModulus> mod);
void set_shrd_mod(const SharedPointer<GFpModulus> mod);
// getters
......@@ -99,14 +99,14 @@ class BOTAN_DLL CurveGFp
* function.
* @result the GFpElement 1, transformed to its m-residue
*/
std::tr1::shared_ptr<GFpElement const> const get_mres_one() const;
SharedPointer<GFpElement const> const get_mres_one() const;
/**
* Get prime modulus of the field of the curve
* @result prime modulus of the field of the curve
*/
BigInt const get_p() const;
/*inline std::tr1::shared_ptr<BigInt> const get_ptr_p() const
/*inline SharedPointer<BigInt> const get_ptr_p() const
{
return mp_p;
}*/
......@@ -119,7 +119,7 @@ class BOTAN_DLL CurveGFp
* Do NOT spread pointers to a GFpModulus over different threads!
* @result a shared pointer to a GFpModulus object
*/
inline std::tr1::shared_ptr<GFpModulus> const get_ptr_mod() const
inline SharedPointer<GFpModulus> const get_ptr_mod() const
{
return mp_mod;
}
......@@ -131,12 +131,12 @@ class BOTAN_DLL CurveGFp
void swap(CurveGFp& other);
private:
std::tr1::shared_ptr<GFpModulus> mp_mod;
SharedPointer<GFpModulus> mp_mod;
GFpElement mA;
GFpElement mB;
mutable std::tr1::shared_ptr<GFpElement> mp_mres_a;
mutable std::tr1::shared_ptr<GFpElement> mp_mres_b;
mutable std::tr1::shared_ptr<GFpElement> mp_mres_one;
mutable SharedPointer<GFpElement> mp_mres_a;
mutable SharedPointer<GFpElement> mp_mres_b;
mutable SharedPointer<GFpElement> mp_mres_one;
};
// relational operators
......
......@@ -39,7 +39,7 @@ class BOTAN_DLL EAC1_1_ADO : public EAC1_1_obj<EAC1_1_ADO>
* Construct a CVC ADO request from a data source
* @param source the data source
*/
EAC1_1_ADO(std::tr1::shared_ptr<DataSource> source);
EAC1_1_ADO(SharedPointer<DataSource> source);
/**
* Create a signed CVC ADO request from to be signed (TBS) data
......
......@@ -59,7 +59,7 @@ class BOTAN_DLL EAC1_1_CVC : public EAC1_1_gen_CVC<EAC1_1_CVC>//Signed_Object
* Construct a CVC from a data source
* @param source the data source
*/
EAC1_1_CVC(std::tr1::shared_ptr<DataSource>& source);
EAC1_1_CVC(SharedPointer<DataSource>& source);
/**
* Construct a CVC from a file
......
......@@ -12,7 +12,6 @@
#include <botan/x509_key.h>
#include <botan/pubkey_enums.h>
#include <botan/cvc_gen_cert.h>
#include <botan/cvc_req.h>
namespace Botan {
......@@ -36,7 +35,7 @@ class BOTAN_DLL EAC1_1_Req : public EAC1_1_gen_CVC<EAC1_1_Req>
* Construct a CVC request from a data source.
* @param source the data source
*/
EAC1_1_Req(std::tr1::shared_ptr<DataSource> source);
EAC1_1_Req(SharedPointer<DataSource> source);
/**
* Construct a CVC request from a DER encoded CVC reqeust file.
......
......@@ -17,6 +17,8 @@
#include <botan/x509_key.h>
#include <botan/pkcs8.h>
#include <memory>
namespace Botan {
/**
......
......@@ -7,14 +7,7 @@
#define BOTAN_FREESTORE_H__
#include <botan/build.h>
#if defined(BOTAN_USE_STD_TR1)
#include <tr1/memory>
#elif defined(BOTAN_USE_BOOST_TR1)
#include <boost/tr1/memory.hpp>
#else
#error "Please choose a TR1 implementation in build.h"
#endif
#include <utils/sharedpointer.h>
namespace Botan {
......@@ -30,7 +23,7 @@ template<typename T>
class BOTAN_DLL SharedPtrConverter
{
public:
typedef std::tr1::shared_ptr<T> SharedPtr;
typedef SharedPointer<T> SharedPtr;
/**
* Construct a null pointer equivalent object.
......
......@@ -14,16 +14,9 @@
#include <botan/bigint.h>
#include <botan/gfp_modulus.h>
#include <utils/sharedpointer.h>
#include <iosfwd>
#if defined(BOTAN_USE_STD_TR1)
#include <tr1/memory>
#elif defined(BOTAN_USE_BOOST_TR1)
#include <boost/tr1/memory.hpp>
#else
#error "Please choose a TR1 implementation in build.h"
#endif
namespace Botan {
struct Illegal_Transformation : public Exception
......@@ -40,7 +33,7 @@ struct Illegal_Transformation : public Exception
class BOTAN_DLL GFpElement
{
private:
std::tr1::shared_ptr<GFpModulus> mp_mod;
SharedPointer<GFpModulus> mp_mod;
mutable BigInt m_value; // ordinary residue or m-residue respectively
mutable BigInt workspace;
......@@ -79,7 +72,7 @@ class BOTAN_DLL GFpElement
* @param value the element value
* @param use_montgm whether this object will use Montgomery multiplication
*/
explicit GFpElement(std::tr1::shared_ptr<GFpModulus> const mod,
explicit GFpElement(SharedPointer<GFpModulus> const mod,
const BigInt& value, bool use_mongm = false);
/**
......@@ -190,7 +183,7 @@ class BOTAN_DLL GFpElement
* the shared GFpModulus objects!
* @result the shared pointer to the GFpModulus of *this
*/
inline std::tr1::shared_ptr<GFpModulus> const get_ptr_mod() const
inline SharedPointer<GFpModulus> const get_ptr_mod() const
{
return mp_mod;
}
......@@ -203,7 +196,7 @@ class BOTAN_DLL GFpElement
* the shared GFpModulus objects!
* @param mod a shared pointer to a GFpModulus that will be held in *this
*/
void set_shrd_mod(std::tr1::shared_ptr<GFpModulus> const mod);
void set_shrd_mod(SharedPointer<GFpModulus> const mod);
/**
* Tells whether this GFpElement is currently transformed to it´ m-residue,
......
......@@ -234,7 +234,7 @@ class BOTAN_DLL PointGFp
* @param mod a shared pointer to a GFpModulus that will
* be held in the members *this
*/
void set_shrd_mod(std::tr1::shared_ptr<GFpModulus> p_mod);
void set_shrd_mod(SharedPointer<GFpModulus> p_mod);
static GFpElement decompress(bool yMod2, GFpElement const& x, const CurveGFp& curve);
......@@ -242,9 +242,9 @@ class BOTAN_DLL PointGFp
static const u32bit GFPEL_WKSP_SIZE = 9;
void ensure_worksp() const;
inline std::tr1::shared_ptr<PointGFp> mult_loop(int l, const BigInt& m,
std::tr1::shared_ptr<PointGFp> H,
std::tr1::shared_ptr<PointGFp> tmp,
inline SharedPointer<PointGFp> mult_loop(int l, const BigInt& m,
SharedPointer<PointGFp> H,
SharedPointer<PointGFp> tmp,
const PointGFp& P);
CurveGFp mC;
......@@ -257,7 +257,7 @@ class BOTAN_DLL PointGFp
mutable bool mZpow2_set;
mutable bool mZpow3_set;
mutable bool mAZpow4_set;
mutable std::tr1::shared_ptr<std::vector<GFpElement> > mp_worksp_gfp_el;
mutable SharedPointer<std::vector<GFpElement> > mp_worksp_gfp_el;
};
......
......@@ -80,8 +80,8 @@ void test_point_turn_on_sp_red_mul()
CHECK_MESSAGE(r1 == r2, "error with point mul after extra turn on sp red mul");
CHECK(r1.get_affine_x().get_value() != BigInt("0"));
std::tr1::shared_ptr<PointGFp> p_r1(new PointGFp(r1));
std::tr1::shared_ptr<PointGFp> p_r2(new PointGFp(r2));
SharedPointer<PointGFp> p_r1(new PointGFp(r1));
SharedPointer<PointGFp> p_r2(new PointGFp(r2));
p_r1->mult2_in_place(); // wird für Fehler nicht gebraucht
p_r2->turn_on_sp_red_mul(); // 1. t_o() macht nur p_r2 kaputt
......@@ -981,7 +981,7 @@ void test_point_worksp()
{
EC_Domain_Params dom_pars(get_EC_Dom_Pars_by_oid("1.3.132.0.8"));
std::tr1::shared_ptr<std::vector<GFpElement> > worksp1;
SharedPointer<std::vector<GFpElement> > worksp1;
assert(worksp1.get() == 0);
{
PointGFp p = dom_pars.get_base_point();
......
......@@ -484,13 +484,13 @@ bool test_gfp_shared_vals()
GFpElement a(p, BigInt("234090"));
GFpElement shcpy_a(1,0);
shcpy_a.share_assign(a);
std::tr1::shared_ptr<GFpModulus> ptr1 = a.get_ptr_mod();
std::tr1::shared_ptr<GFpModulus> ptr2 = shcpy_a.get_ptr_mod();
SharedPointer<GFpModulus> ptr1 = a.get_ptr_mod();
SharedPointer<GFpModulus> ptr2 = shcpy_a.get_ptr_mod();
CHECK_MESSAGE(ptr1.get() == ptr2.get(), "shared pointers for moduli aren´t equal");
GFpElement b(1,0);
b = a; // create a non shared copy
std::tr1::shared_ptr<GFpModulus> ptr_b_p = b.get_ptr_mod();
SharedPointer<GFpModulus> ptr_b_p = b.get_ptr_mod();
CHECK_MESSAGE(ptr1.get() != ptr_b_p.get(), "non shared pointers for moduli are equal");
a.turn_on_sp_red_mul();
......@@ -513,15 +513,15 @@ bool test_gfp_shared_vals()
}
swap(a,shcpy_a);
std::tr1::shared_ptr<GFpModulus> ptr3 = a.get_ptr_mod();
std::tr1::shared_ptr<GFpModulus> ptr4 = shcpy_a.get_ptr_mod();
SharedPointer<GFpModulus> ptr3 = a.get_ptr_mod();
SharedPointer<GFpModulus> ptr4 = shcpy_a.get_ptr_mod();
CHECK_MESSAGE(ptr3.get() == ptr4.get(), "shared pointers for moduli aren´t equal after swap");
CHECK(ptr1.get() == ptr4.get());
CHECK(ptr2.get() == ptr3.get());
swap(a,b);
std::tr1::shared_ptr<GFpModulus> ptr_a = a.get_ptr_mod();
std::tr1::shared_ptr<GFpModulus> ptr_b = shcpy_a.get_ptr_mod();
SharedPointer<GFpModulus> ptr_a = a.get_ptr_mod();
SharedPointer<GFpModulus> ptr_b = shcpy_a.get_ptr_mod();
CHECK(ptr_a.get() == ptr_b_p.get());
CHECK(ptr_b.get() == ptr3.get());
return pass;
......
......@@ -12,7 +12,7 @@
namespace Botan {
EAC1_1_ADO::EAC1_1_ADO(std::tr1::shared_ptr<DataSource> in)
EAC1_1_ADO::EAC1_1_ADO(SharedPointer<DataSource> in)
{
init(in);
do_decode();
......@@ -20,7 +20,7 @@ EAC1_1_ADO::EAC1_1_ADO(std::tr1::shared_ptr<DataSource> in)
EAC1_1_ADO::EAC1_1_ADO(const std::string& in)
{
std::tr1::shared_ptr<DataSource> stream(new DataSource_Stream(in, true));
SharedPointer<DataSource> stream(new DataSource_Stream(in, true));
init(stream);
do_decode();
}
......@@ -41,7 +41,7 @@ void EAC1_1_ADO::force_decode()
.end_cons()
.get_contents();
std::tr1::shared_ptr<DataSource> req_source(new DataSource_Memory(req_bits));
SharedPointer<DataSource> req_source(new DataSource_Memory(req_bits));
m_req = EAC1_1_Req(req_source);
sig_algo = m_req.sig_algo;
}
......
......@@ -39,7 +39,7 @@ class BOTAN_DLL EAC1_1_ADO : public EAC1_1_obj<EAC1_1_ADO>
* Construct a CVC ADO request from a data source
* @param source the data source
*/
EAC1_1_ADO(std::tr1::shared_ptr<DataSource> source);
EAC1_1_ADO(SharedPointer<DataSource> source);
/**
* Create a signed CVC ADO request from to be signed (TBS) data
......
......@@ -38,7 +38,7 @@ EAC1_1_CVC EAC1_1_CVC_CA::make_cert(std::auto_ptr<PK_Signer> signer,
EAC1_1_CVC::build_cert_body(tbs),
rng);
std::tr1::shared_ptr<DataSource> source(new DataSource_Memory(signed_cert));
SharedPointer<DataSource> source(new DataSource_Memory(signed_cert));
return EAC1_1_CVC(source);
}
......
......@@ -78,7 +78,7 @@ void EAC1_1_CVC::force_decode()
/*
* CVC Certificate Constructor
*/
EAC1_1_CVC::EAC1_1_CVC(std::tr1::shared_ptr<DataSource>& in)
EAC1_1_CVC::EAC1_1_CVC(SharedPointer<DataSource>& in)
{
init(in);
self_signed = false;
......@@ -87,7 +87,7 @@ EAC1_1_CVC::EAC1_1_CVC(std::tr1::shared_ptr<DataSource>& in)
EAC1_1_CVC::EAC1_1_CVC(const std::string& in)
{
std::tr1::shared_ptr<DataSource> stream(new DataSource_Stream(in, true));
SharedPointer<DataSource> stream(new DataSource_Stream(in, true));
init(stream);
self_signed = false;
do_decode();
......
......@@ -59,7 +59,7 @@ class BOTAN_DLL EAC1_1_CVC : public EAC1_1_gen_CVC<EAC1_1_CVC>//Signed_Object
* Construct a CVC from a data source
* @param source the data source
*/
EAC1_1_CVC(std::tr1::shared_ptr<DataSource>& source);
EAC1_1_CVC(SharedPointer<DataSource>& source);
/**
* Construct a CVC from a file
......
......@@ -50,7 +50,7 @@ void EAC1_1_Req::force_decode()
#endif
}
EAC1_1_Req::EAC1_1_Req(std::tr1::shared_ptr<DataSource> in)
EAC1_1_Req::EAC1_1_Req(SharedPointer<DataSource> in)
{
init(in);
self_signed = true;
......@@ -59,7 +59,7 @@ EAC1_1_Req::EAC1_1_Req(std::tr1::shared_ptr<DataSource> in)
EAC1_1_Req::EAC1_1_Req(const std::string& in)
{
std::tr1::shared_ptr<DataSource> stream(new DataSource_Stream(in, true));
SharedPointer<DataSource> stream(new DataSource_Stream(in, true));
init(stream);
self_signed = true;
do_decode();
......
......@@ -35,7 +35,7 @@ class BOTAN_DLL EAC1_1_Req : public EAC1_1_gen_CVC<EAC1_1_Req>
* Construct a CVC request from a data source.
* @param source the data source
*/
EAC1_1_Req(std::tr1::shared_ptr<DataSource> source);
EAC1_1_Req(SharedPointer<DataSource> source);
/**
* Construct a CVC request from a DER encoded CVC reqeust file.
......
......@@ -131,7 +131,7 @@ EAC1_1_Req create_cvc_req(Private_Key const& key,
.get_contents();
MemoryVector<byte> signed_cert = EAC1_1_gen_CVC<EAC1_1_Req>::make_signed(signer, EAC1_1_gen_CVC<EAC1_1_Req>::build_cert_body(tbs), rng);
std::tr1::shared_ptr<DataSource> source(new DataSource_Memory(signed_cert));
SharedPointer<DataSource> source(new DataSource_Memory(signed_cert));
return EAC1_1_Req(source);
}
......@@ -151,7 +151,7 @@ EAC1_1_ADO create_ado_req(Private_Key const& key,
SecureVector<byte> tbs_bits = req.BER_encode();
tbs_bits.append(DER_Encoder().encode(car).get_contents());
MemoryVector<byte> signed_cert = EAC1_1_ADO::make_signed(signer, tbs_bits, rng);
std::tr1::shared_ptr<DataSource> source(new DataSource_Memory(signed_cert));
SharedPointer<DataSource> source(new DataSource_Memory(signed_cert));
return EAC1_1_ADO(source);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment