aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-04-15 09:25:29 -0700
committerJeff Garzik <jgarzik@exmulti.com>2012-04-15 09:25:29 -0700
commitfced2231f89fd86c2c4abe7426b0a493a94bd444 (patch)
tree8a728d50df9335c6dbf0a76f8cb247533bd7abce
parent9ea8e60a0c8531e647521531d4b0fed757abc331 (diff)
parentb3a6e613fc4c3261ff5a28f77b11398e60dca82a (diff)
Merge pull request #1084 from dooglus/validate_secret
importprivkey doesn't check that it is given a private key
-rw-r--r--src/base58.h10
-rw-r--r--src/test/key_tests.cpp12
2 files changed, 17 insertions, 5 deletions
diff --git a/src/base58.h b/src/base58.h
index 755e34c418..7fefbc5d74 100644
--- a/src/base58.h
+++ b/src/base58.h
@@ -396,6 +396,16 @@ public:
return fExpectTestNet == fTestNet && (vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1));
}
+ bool SetString(const char* pszSecret)
+ {
+ return CBase58Data::SetString(pszSecret) && IsValid();
+ }
+
+ bool SetString(const std::string& strSecret)
+ {
+ return SetString(strSecret.c_str());
+ }
+
CBitcoinSecret(const CSecret& vchSecret, bool fCompressed)
{
SetSecret(vchSecret, fCompressed);
diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp
index bc8759b6fa..a6dab623b0 100644
--- a/src/test/key_tests.cpp
+++ b/src/test/key_tests.cpp
@@ -14,6 +14,7 @@ static const string strSecret1 ("5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtm
static const string strSecret2 ("5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3");
static const string strSecret1C("Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw");
static const string strSecret2C("L3Hq7a8FEQwJkW1M2GNKDW28546Vp5miewcCzSqUD9kCAXrJdS3g");
+static const string strAddress1("1HV9Lc3sNHZxwj4Zk6fB38tEmBryq2cBiF");
#ifdef KEY_TESTS_DUMPINFO
void dumpKeyInfo(uint256 privkey)
@@ -47,11 +48,12 @@ BOOST_AUTO_TEST_SUITE(key_tests)
BOOST_AUTO_TEST_CASE(key_test1)
{
- CBitcoinSecret bsecret1, bsecret2, bsecret1C, bsecret2C;
- bsecret1.SetString (strSecret1);
- bsecret2.SetString (strSecret2);
- bsecret1C.SetString(strSecret1C);
- bsecret2C.SetString(strSecret2C);
+ CBitcoinSecret bsecret1, bsecret2, bsecret1C, bsecret2C, baddress1;
+ BOOST_CHECK( bsecret1.SetString (strSecret1));
+ BOOST_CHECK( bsecret2.SetString (strSecret2));
+ BOOST_CHECK( bsecret1C.SetString(strSecret1C));
+ BOOST_CHECK( bsecret2C.SetString(strSecret2C));
+ BOOST_CHECK(!baddress1.SetString(strAddress1));
bool fCompressed;
CSecret secret1 = bsecret1.GetSecret (fCompressed);