fixed compilation errors

This commit is contained in:
TLINDEN
2013-11-29 20:02:27 +01:00
parent a9b2796af2
commit 6dc134c005
2 changed files with 87 additions and 75 deletions

View File

@@ -37,25 +37,25 @@ Key::Key(bool generate) {
Key::Key(const string& passphrase) { Key::Key(const string& passphrase) {
stored = false; stored = false;
K = pcpkey_new(); K = pcpkey_new();
K = pcpkey_encrypt(K, passphrase.c_str()); K = pcpkey_encrypt(K, (char *)passphrase.c_str());
} }
Key::Key(const string& passphrase, Key::Key(const string& passphrase,
const string& owner, const string& owner,
const string& mail) { const string& mail) {
stored = false; stored = false;
_k = pcpkey_new(); pcp_key_t *_K = pcpkey_new();
K = pcpkey_encrypt(_K, passphrase.c_str()); K = pcpkey_encrypt(_K, (char *)passphrase.c_str());
free(_k);
memcpy(K->owner, owner.c_str(), owner.length()+1); memcpy(K->owner, owner.c_str(), owner.length()+1);
memcpy(K->mail, mail.c_str(), mail.length()+1); memcpy(K->mail, mail.c_str(), mail.length()+1);
free(_K);
} }
Key::(const Key &k) { Key::Key(const Key &k) {
K = k.K; K = k.K;
} }
Key::Key(const pcp_key_t *k) { Key::Key(pcp_key_t *k) {
stored = false; stored = false;
K = k; K = k;
} }
@@ -66,7 +66,7 @@ Key::~Key() {
} }
} }
const Key::Key& operator = (const Key &k) { Key::Key& Key::operator = (const Key &k) {
K = k.K; K = k.K;
return *this; return *this;
} }
@@ -76,32 +76,33 @@ istream& operator>>(istream& input, Key& k) {
input >> z85; input >> z85;
if(z85.length() == 0) if(z85.length() == 0)
throw exception("Error: zero length input"); throw pcp::exception("Error: zero length input");
size_t clen; size_t clen;
unsigned char *z85decoded = pcp_z85_decode(z85.c_str(), &clen); unsigned char *z85decoded = pcp_z85_decode((char *)z85.c_str(), &clen);
if(z85decoded == NULL) if(z85decoded == NULL)
throw exception("Error: could not decode input - it's probably not Z85.\n"); throw pcp::exception("Error: could not decode input - it's probably not Z85.\n");
if(clen != PCP_RAW_KEYSIZE) { if(clen != PCP_RAW_KEYSIZE) {
free(z85decoded); free(z85decoded);
throw exception("Error: decoded input didn't result to a proper sized key!" char m[256];
+ "(got " + clen + " bytes)\n"); sprintf(m, "Error: decoded input didn't result to a proper sized key (got %ld bytes)!\n", clen);
throw pcp::exception(string(m));
} }
// all good now, import the blob // all good now, import the blob
pcp_key_t *key = ucmalloc(sizeof(pcp_key_t)); pcp_key_t *key = (pcp_key_t *)ucmalloc(sizeof(pcp_key_t));
memcpy(key, z85decoded, PCP_RAW_KEYSIZE); memcpy(key, z85decoded, PCP_RAW_KEYSIZE);
key2native(key); key2native(key);
if(pcp_sanitycheck_key(key) != 0) { if(pcp_sanitycheck_key(key) != 0) {
free(key); free(key);
free(z85decoded); free(z85decoded);
throw exception(); throw pcp::exception();
} }
k.K = key; k = Key(key);
free(key); free(key);
return input; return input;
@@ -110,7 +111,7 @@ istream& operator>>(istream& input, Key& k) {
ostream& operator<<(ostream& output, Key& k) { ostream& operator<<(ostream& output, Key& k) {
size_t zlen; size_t zlen;
pcp_key_t *key = k.K; pcp_key_t *key = k.get_key();
key2be(key); key2be(key);
void *blob = ucmalloc(PCP_RAW_KEYSIZE); void *blob = ucmalloc(PCP_RAW_KEYSIZE);
@@ -118,7 +119,7 @@ ostream& operator<<(ostream& output, Key& k) {
char *z85encoded = pcp_z85_encode((unsigned char*)blob, PCP_RAW_KEYSIZE, &zlen); char *z85encoded = pcp_z85_encode((unsigned char*)blob, PCP_RAW_KEYSIZE, &zlen);
if(PCP_ERRSET == 1) if(PCP_ERRSET == 1)
throw exception(); throw pcp::exception();
key2native(key); key2native(key);
@@ -128,7 +129,7 @@ ostream& operator<<(ostream& output, Key& k) {
time_t t = (time_t)key->ctime; time_t t = (time_t)key->ctime;
c = localtime(&t); c = localtime(&t);
char *out = ucmalloc(2048); char *out = (char *)ucmalloc(2048);
sprintf(out, "%s\n", PCP_KEY_HEADER); sprintf(out, "%s\n", PCP_KEY_HEADER);
output << out; output << out;
@@ -167,13 +168,13 @@ ostream& operator<<(ostream& output, Key& k) {
} }
void Key::encrypt(const string& passphrase) { void Key::encrypt(const string& passphrase) {
K = pcpkey_encrypt(K, passphrase.c_str()); K = pcpkey_encrypt(K, (char *)passphrase.c_str());
if(PCP_ERRSET == 1) if(PCP_ERRSET == 1)
throw exception(); throw exception();
} }
void Key::decrypt(const string& passphrase) { void Key::decrypt(const string& passphrase) {
K = pcpkey_decrypt(K, passphrase.c_str()); K = pcpkey_decrypt(K, (char *)passphrase.c_str());
if(PCP_ERRSET == 1) if(PCP_ERRSET == 1)
throw exception(); throw exception();
} }
@@ -183,17 +184,17 @@ PubKey Key::get_public() {
} }
string Key::get_id() { string Key::get_id() {
string id = K.id; string id = K->id;
return id; return id;
} }
string Key::get_owner() { string Key::get_owner() {
string o = K.owner; string o = K->owner;
return o; return o;
} }
string Key::get_mail() { string Key::get_mail() {
string m = K.mail; string m = K->mail;
return m; return m;
} }
@@ -239,11 +240,11 @@ PubKey::PubKey() {
K = NULL; K = NULL;
} }
PubKey::(const PubKey &k) { PubKey::PubKey(const PubKey &k) {
K = k.K; K = k.K;
} }
PubKey::PubKey(const pcp_pubkey_t *k) { PubKey::PubKey(pcp_pubkey_t *k) {
stored = false; stored = false;
K = k; K = k;
} }
@@ -254,7 +255,7 @@ PubKey::~PubKey() {
} }
} }
const PubKey::PubKey& operator = (const PubKey &k) { PubKey::PubKey& PubKey::operator = (const PubKey &k) {
K = k.K; K = k.K;
return *this; return *this;
} }
@@ -264,32 +265,33 @@ istream& operator>>(istream& input, PubKey& k) {
input >> z85; input >> z85;
if(z85.length() == 0) if(z85.length() == 0)
throw exception("Error: zero length input"); throw pcp::exception("Error: zero length input");
size_t clen; size_t clen;
unsigned char *z85decoded = pcp_z85_decode(z85.c_str(), &clen); unsigned char *z85decoded = pcp_z85_decode((char *)z85.c_str(), &clen);
if(z85decoded == NULL) if(z85decoded == NULL)
throw exception("Error: could not decode input - it's probably not Z85.\n"); throw pcp::exception("Error: could not decode input - it's probably not Z85.\n");
if(clen != PCP_RAW_PUBKEYSIZE) { if(clen != PCP_RAW_PUBKEYSIZE) {
free(z85decoded); free(z85decoded);
throw exception("Error: decoded input didn't result to a proper sized key!" char m[256];
+ "(got " + clen + " bytes)\n"); sprintf(m, "Error: decoded input didn't result to a proper sized key (got %ld bytes)!\n", clen);
throw pcp::exception(string(m));
} }
// all good now, import the blob // all good now, import the blob
pcp_pubkey_t *key = ucmalloc(sizeof(pcp_pubkey_t)); pcp_pubkey_t *key = (pcp_pubkey_t *)ucmalloc(sizeof(pcp_pubkey_t));
memcpy(key, z85decoded, PCP_RAW_PUBKEYSIZE); memcpy(key, z85decoded, PCP_RAW_PUBKEYSIZE);
pubkey2native(key); pubkey2native(key);
if(pcp_sanitycheck_pub(key) != 0) { if(pcp_sanitycheck_pub(key) != 0) {
free(key); free(key);
free(z85decoded); free(z85decoded);
throw exception(); throw pcp::exception();
} }
k.K = key; k = PubKey(key);
free(key); free(key);
return input; return input;
@@ -298,7 +300,7 @@ istream& operator>>(istream& input, PubKey& k) {
ostream& operator<<(ostream& output, PubKey& k) { ostream& operator<<(ostream& output, PubKey& k) {
size_t zlen; size_t zlen;
pcp_pubkey_t *key = k.K; pcp_pubkey_t *key = k.get_key();
pubkey2be(key); pubkey2be(key);
void *blob = ucmalloc(PCP_RAW_PUBKEYSIZE); void *blob = ucmalloc(PCP_RAW_PUBKEYSIZE);
@@ -306,7 +308,7 @@ ostream& operator<<(ostream& output, PubKey& k) {
char *z85encoded = pcp_z85_encode((unsigned char*)blob, PCP_RAW_PUBKEYSIZE, &zlen); char *z85encoded = pcp_z85_encode((unsigned char*)blob, PCP_RAW_PUBKEYSIZE, &zlen);
if(PCP_ERRSET == 1) if(PCP_ERRSET == 1)
throw exception(); throw pcp::exception();
pubkey2native(key); pubkey2native(key);
@@ -316,7 +318,7 @@ ostream& operator<<(ostream& output, PubKey& k) {
time_t t = (time_t)key->ctime; time_t t = (time_t)key->ctime;
c = localtime(&t); c = localtime(&t);
char *out = ucmalloc(2048); char *out = (char *)ucmalloc(2048);
sprintf(out, "%s\n", PCP_PUBKEY_HEADER); sprintf(out, "%s\n", PCP_PUBKEY_HEADER);
output << out; output << out;
@@ -364,8 +366,9 @@ ostream& operator<<(ostream& output, PubKey& k) {
char *r = pcppubkey_get_art(key); char *r = pcppubkey_get_art(key);
output << " Random Art ID: "; output << " Random Art ID: ";
int rlen = strlen(r);
for (i=0; i<strlen(r); ++i) { for (i=0; i<rlen; ++i) {
if(r[i] == '\n') { if(r[i] == '\n') {
output << "\n "; output << "\n ";
} }
@@ -388,17 +391,17 @@ ostream& operator<<(ostream& output, PubKey& k) {
} }
string PubKey::get_id() { string PubKey::get_id() {
string id = K.id; string id = K->id;
return id; return id;
} }
string PubKey::get_owner() { string PubKey::get_owner() {
string o = K.owner; string o = K->owner;
return o; return o;
} }
string PubKey::get_mail() { string PubKey::get_mail() {
string m = K.mail; string m = K->mail;
return m; return m;
} }

View File

@@ -43,7 +43,7 @@ namespace pcp {
msg = PCP_ERR; msg = PCP_ERR;
} }
if(errno) { if(errno) {
msg += "\nError: " + strerror(errno) + "\n"; msg += std::string("\nError: ") + std::string(strerror(errno)) + std::string("\n");
} }
return msg; return msg;
} }
@@ -53,6 +53,40 @@ namespace pcp {
}; };
class PubKey {
private:
pcp_pubkey_t *K;
bool stored;
public:
// constructors
PubKey();
PubKey(const PubKey &k);
PubKey(pcp_pubkey_t *k);
// destructors
~PubKey();
// operators
PubKey& operator = (const PubKey &k);
std::string get_id();
std::string get_owner();
std::string get_mail();
pcp_pubkey_t *get_key();
void is_stored(bool s);
bool is_stored();
};
std::istream& operator>>(std::istream& input, PubKey& k);
std::ostream& operator<<(std::ostream& output, PubKey& k);
class Key { class Key {
private: private:
pcp_key_t *K; pcp_key_t *K;
@@ -67,15 +101,14 @@ namespace pcp {
const std::string& owner, const std::string& owner,
const std::string& mail); const std::string& mail);
Key(const Key &k); Key(const Key &k);
Key(const pcp_key_t *k); Key(pcp_key_t *k);
// destructors // destructors
~Key(); ~Key();
// operators // operators
const Key& operator = (const Key &k); Key& operator = (const Key &k);
std::istream& operator>>(std::istream& input, Key& k); // import
std::ostream& operator<<(std::ostream& output, Key& k); // export
// methods // methods
void encrypt(const std::string& passphrase); void encrypt(const std::string& passphrase);
@@ -93,33 +126,9 @@ namespace pcp {
bool is_encrypted(); bool is_encrypted();
}; };
// << and >> operators
class PubKey { std::istream& operator>>(std::istream& input, Key& k);
private: std::ostream& operator<<(std::ostream& output, Key& k);
pcp_pubkey_t *K;
bool stored;
public:
// constructors
PubKey();
PubKey(const PubKey &k);
PubKey(const pcp_pubkey_t *k);
// destructors
~PubKey();
// operators
const PubKey& operator = (const PubKey &k);
std::istream& operator>>(std::istream& input, PubKey& k); // import
std::ostream& operator<<(std::ostream& output, PubKey& k); // export
std::string get_id();
std::string get_owner();
std::string get_mail();
pcp_pubkey_t *get_key();
void is_stored(bool s);
bool is_stored();
};
}; };