providertest.cpp

The code below shows some simple operations on a QCA::Provider object, including use of iterators and some member functions.

00001 /*
00002  Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
00003 
00004  Permission is hereby granted, free of charge, to any person obtaining a copy
00005  of this software and associated documentation files (the "Software"), to deal
00006  in the Software without restriction, including without limitation the rights
00007  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  copies of the Software, and to permit persons to whom the Software is
00009  furnished to do so, subject to the following conditions:
00010 
00011  The above copyright notice and this permission notice shall be included in
00012  all copies or substantial portions of the Software.
00013 
00014  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00017  AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00018  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00019  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00020 */
00021 
00022 // QtCrypto has the declarations for all of QCA
00023 #include <QtCrypto>
00024 #include <QCoreApplication>
00025 
00026 #include <iostream>
00027 #include <qstringlist.h>
00028 
00029 int main(int argc, char **argv)
00030 {
00031     // the Initializer object sets things up, and
00032     // also does cleanup when it goes out of scope
00033     QCA::Initializer init;
00034 
00035     QCoreApplication app(argc, argv);
00036 
00037     // get all the available providers loaded.
00038     // you don't normally need this (because you test using isSupported())
00039     // but this is a special case.
00040     QCA::scanForPlugins();
00041 
00042     // this gives us all the plugin providers as a list
00043     QCA::ProviderList qcaProviders = QCA::providers();
00044     for (int i = 0; i < qcaProviders.size(); ++i) {
00045         // each provider has a name, which we can display
00046         std::cout << qcaProviders[i]->name().toLatin1().data() << ": ";
00047         // ... and also a list of features
00048         QStringList capabilities = qcaProviders[i]->features();
00049         // we turn the string list back into a single string,
00050         // and display it as well
00051         std::cout << capabilities.join(", ").toLatin1().data() << std::endl;
00052     }
00053 
00054     // Note that the default provider isn't included in
00055     // the result of QCA::providers()
00056     std::cout << "default: ";
00057     // However it is still possible to get the features
00058     // supported by the default provider
00059     QStringList capabilities = QCA::defaultFeatures();
00060     std::cout << capabilities.join(", ").toLatin1().data() << std::endl;
00061     return 0;
00062 }
00063 

Generated on Thu Sep 6 19:13:35 2007 for Qt Cryptographic Architecture by  doxygen 1.5.2