diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kolabcontact.cpp | 11 | ||||
-rw-r--r-- | src/kolabcontact.h | 33 | ||||
-rw-r--r-- | src/xcardconversions.h | 61 |
3 files changed, 74 insertions, 31 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; } |