summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2012-04-04 09:43:52 (GMT)
committerChristian Mollekopf <chrigi_1@fastmail.fm>2012-04-04 09:43:52 (GMT)
commit5be9ac77cc026fe2435d4d82025c93764454f555 (patch)
tree05f967c0e2081cc5eb841493478fdd9bde41d45e
parentdf09a3cd73cf73bcaac45a4dc3f23776d066a04e (diff)
downloadlibkolabxml-5be9ac77cc026fe2435d4d82025c93764454f555.tar.gz
Use the more general and standards compliant key property also in the API.
-rw-r--r--src/kolabcontact.cpp11
-rw-r--r--src/kolabcontact.h33
-rw-r--r--src/xcardconversions.h61
-rw-r--r--tests/bindingstest.cpp7
4 files changed, 79 insertions, 33 deletions
diff --git a/src/kolabcontact.cpp b/src/kolabcontact.cpp
index a959a2c..4f68b72 100644
--- a/src/kolabcontact.cpp
+++ b/src/kolabcontact.cpp
@@ -153,6 +153,7 @@ struct Contact::Private
std::vector<std::string> emailAddresses;
int emailAddressPreferredIndex;
std::vector<Geo> gpsPos;
+ std::vector<Key> keys;
Crypto crypto;
std::vector<CustomProperty> customProperties;
};
@@ -441,6 +442,16 @@ std::vector< Geo > Contact::gpsPos() const
return d->gpsPos;
}
+void Contact::setKeys(const std::vector<Key> &keys)
+{
+ d->keys = keys;
+}
+
+std::vector<Key> Contact::keys() const
+{
+ return d->keys;
+}
+
void Contact::setCrypto(const Kolab::Crypto& c)
{
d->crypto = c;
diff --git a/src/kolabcontact.h b/src/kolabcontact.h
index e4164dd..30d3814 100644
--- a/src/kolabcontact.h
+++ b/src/kolabcontact.h
@@ -212,26 +212,18 @@ struct Crypto {
};
Crypto(): mCryptoTypes(0), mSignPref(Ask), mEncryptPref(Ask){};
bool operator==(const Crypto &other) const { return mCryptoTypes == other.mCryptoTypes &&
- mPGPKey == other.mPGPKey &&
- mSMIMEKey == other.mSMIMEKey &&
mSignPref == other.mSignPref &&
mEncryptPref == other.mEncryptPref; };
- bool isValid() const { return !(!mCryptoTypes && mPGPKey.empty() && mSMIMEKey.empty()); };
+ bool isValid() const { return mCryptoTypes; };
void setAllowed(int cryptoTypes) { mCryptoTypes = cryptoTypes; };
int allowed() const { return mCryptoTypes; };
- void setPGPKey(const std::string &k) { mPGPKey = k; };
- std::string pgpKey() const { return mPGPKey; };
- void setSMIMEKey(const std::string &k) { mSMIMEKey = k; };
- std::string smimeKey() const { return mSMIMEKey; };
void setSignPref(CryptoPref p) { mSignPref = p; };
CryptoPref signPref() const { return mSignPref; };
void setEncryptPref(CryptoPref p) { mEncryptPref = p; };
CryptoPref encryptPref() const { return mEncryptPref; };
private:
int mCryptoTypes;
- std::string mPGPKey;
- std::string mSMIMEKey;
CryptoPref mSignPref;
CryptoPref mEncryptPref;
};
@@ -246,6 +238,26 @@ struct Geo {
double longitude;
};
+struct Key {
+ enum KeyType {
+ Invalid,
+ PGP,
+ PKCS7_MIME
+ };
+ Key(): keytype(Invalid) {};
+ Key(const std::string &k, KeyType type)
+ : mKey(k), keytype(type) {};
+
+ bool operator==(const Key &other) const{ return (mKey == other.mKey && keytype == other.keytype);};
+
+ KeyType type() const { return keytype; };
+ std::string key() const { return mKey; };
+
+private:
+ std::string mKey;
+ KeyType keytype;
+};
+
class DistList {
public:
@@ -364,6 +376,9 @@ public:
void setGPSpos(const std::vector<Geo> &);
std::vector<Geo> gpsPos() const;
+ void setKeys(const std::vector<Key> &);
+ std::vector<Key> keys() const;
+
void setCrypto(const Crypto &);
Crypto crypto() const;
diff --git a/src/xcardconversions.h b/src/xcardconversions.h
index 501eb1a..8125ff6 100644
--- a/src/xcardconversions.h
+++ b/src/xcardconversions.h
@@ -679,20 +679,32 @@ void writeCard<Kolab::Contact>(vcard_4_0::vcard &vcard, const Kolab::Contact &co
allowed.text(seq);
crypto.allowed(allowed);
}
+
+ crypto.encryptpref(fromCryptoPref(c.encryptPref()));
+ crypto.signpref(fromCryptoPref(c.signPref()));
+
+ vcard.x_crypto(crypto);
+ }
+
+ if (!contact.keys().empty()) {
vcard_4_0::vcard::key_sequence keys;
- if (!c.pgpKey().empty()) {
- keys.push_back(vcard_4_0::keyPropType(uriInlineEncoding(c.pgpKey(), MIME_PGP_KEYS)));
- }
- if (!c.smimeKey().empty()) {
- keys.push_back(vcard_4_0::keyPropType(uriInlineEncoding(c.smimeKey(), MIME_PKCS7_MIME)));
+ BOOST_FOREACH (const Kolab::Key &k, contact.keys()) {
+ switch (k.type()) {
+ case Kolab::Key::PGP:
+ keys.push_back(vcard_4_0::keyPropType(uriInlineEncoding(k.key(), MIME_PGP_KEYS)));
+ break;
+ case Kolab::Key::PKCS7_MIME:
+ keys.push_back(vcard_4_0::keyPropType(uriInlineEncoding(k.key(), MIME_PKCS7_MIME)));
+ break;
+ default:
+ LOG("Unhandled/Invalid keytype");
+ break;
+ }
}
+
if (!keys.empty()) {
vcard.key(keys);
}
- crypto.encryptpref(fromCryptoPref(c.encryptPref()));
- crypto.signpref(fromCryptoPref(c.signPref()));
-
- vcard.x_crypto(crypto);
}
@@ -999,19 +1011,7 @@ boost::shared_ptr<Kolab::Contact> readCard <Kolab::Contact> (const vcard_4_0::Vc
}
c.setAllowed(allowed);
}
- if (!vcard.key().empty()) {
- BOOST_FOREACH(const vcard_4_0::keyPropType &k, vcard.key()) {
- std::string mimetype;
- const std::string &key = uriInlineDecoding(k.uri(), mimetype);
- if (mimetype == MIME_PGP_KEYS) {
- c.setPGPKey(key);
- } else if (mimetype == MIME_PKCS7_MIME) {
- c.setSMIMEKey(key);
- } else {
- WARNING("wrong mimetype on key");
- }
- }
- }
+
if (crypto.encryptpref()) {
c.setEncryptPref(toCryptoPref(crypto.encryptpref()->text()));
}
@@ -1020,6 +1020,23 @@ boost::shared_ptr<Kolab::Contact> readCard <Kolab::Contact> (const vcard_4_0::Vc
}
contact->setCrypto(c);
}
+
+ if (!vcard.key().empty()) {
+ std::string mimetype;
+ std::vector<Kolab::Key> keys;
+ BOOST_FOREACH(const vcard_4_0::keyPropType &k, vcard.key()) {
+ const std::string &key = uriInlineDecoding(k.uri(), mimetype);
+ if (mimetype == MIME_PGP_KEYS) {
+ keys.push_back(Kolab::Key(key, Kolab::Key::PGP));
+ } else if (mimetype == MIME_PKCS7_MIME) {
+ keys.push_back(Kolab::Key(key, Kolab::Key::PKCS7_MIME));
+ } else {
+ WARNING("wrong mimetype on key");
+ }
+ }
+ contact->setKeys(keys);
+ }
+
return contact;
}
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index 6f1cf6c..c943a20 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -427,11 +427,13 @@ void BindingsTest::contactCompletness()
c.setGPSpos(geo);
Kolab::Crypto crypto;
crypto.setAllowed(Kolab::Crypto::PGPinline | Kolab::Crypto::SMIMEopaque);
- crypto.setPGPKey("pgp");
crypto.setSignPref(Kolab::Crypto::IfPossible);
crypto.setEncryptPref(Kolab::Crypto::Never);
- crypto.setSMIMEKey("smime");
c.setCrypto(crypto);
+ std::vector<Kolab::Key> keys;
+ keys.push_back(Kolab::Key("pgp", Kolab::Key::PGP));
+ keys.push_back(Kolab::Key("smime", Kolab::Key::PKCS7_MIME));
+ c.setKeys(keys);
std::vector<Kolab::CustomProperty> properties;
properties.push_back(Kolab::CustomProperty("ident", "value"));
@@ -469,6 +471,7 @@ void BindingsTest::contactCompletness()
QCOMPARE(e.emailAddresses(), c.emailAddresses());
QCOMPARE(e.emailAddressPreferredIndex(), c.emailAddressPreferredIndex());
QCOMPARE(e.gpsPos(), c.gpsPos());
+ QCOMPARE(e.keys(), c.keys());
QCOMPARE(e.crypto(), c.crypto());
QCOMPARE(e.customProperties(), c.customProperties());
}