File indexing completed on 2024-05-05 04:45:04

0001 /*
0002  * Copyright (C) 2003-2008  Justin Karneges <justin@affinix.com>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Lesser General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Lesser General Public
0015  * License along with this library; if not, write to the Free Software
0016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
0017  */
0018 
0019 #include "mykeystoreentry.h"
0020 #include "utils.h"
0021 
0022 using namespace QCA;
0023 
0024 namespace gpgQCAPlugin {
0025 
0026 MyKeyStoreEntry::MyKeyStoreEntry(const PGPKey &_pub, const PGPKey &_sec, Provider *p)
0027     : KeyStoreEntryContext(p)
0028 {
0029     pub = _pub;
0030     sec = _sec;
0031     if (!sec.isNull())
0032         item_type = KeyStoreEntry::TypePGPSecretKey;
0033     else
0034         item_type = KeyStoreEntry::TypePGPPublicKey;
0035 }
0036 
0037 MyKeyStoreEntry::MyKeyStoreEntry(const MyKeyStoreEntry &from)
0038     : KeyStoreEntryContext(from)
0039 {
0040 }
0041 
0042 MyKeyStoreEntry::~MyKeyStoreEntry()
0043 {
0044 }
0045 
0046 Provider::Context *MyKeyStoreEntry::clone() const
0047 {
0048     return new MyKeyStoreEntry(*this);
0049 }
0050 
0051 KeyStoreEntry::Type MyKeyStoreEntry::type() const
0052 {
0053     return item_type;
0054 }
0055 
0056 QString MyKeyStoreEntry::name() const
0057 {
0058     return pub.primaryUserId();
0059 }
0060 
0061 QString MyKeyStoreEntry::id() const
0062 {
0063     return pub.keyId();
0064 }
0065 
0066 QString MyKeyStoreEntry::storeId() const
0067 {
0068     return _storeId;
0069 }
0070 
0071 QString MyKeyStoreEntry::storeName() const
0072 {
0073     return _storeName;
0074 }
0075 
0076 PGPKey MyKeyStoreEntry::pgpSecretKey() const
0077 {
0078     return sec;
0079 }
0080 
0081 PGPKey MyKeyStoreEntry::pgpPublicKey() const
0082 {
0083     return pub;
0084 }
0085 
0086 QString MyKeyStoreEntry::serialize() const
0087 {
0088     // we only serialize the key id.  this means the keyring
0089     //   must be available to restore the data
0090     QStringList out;
0091     out += escape_string(QStringLiteral("qca-gnupg-1"));
0092     out += escape_string(pub.keyId());
0093     return out.join(QStringLiteral(":"));
0094 }
0095 
0096 } // end namespace gpgQCAPlugin