qca_export,tools,qpipe.h,support,provider,core,qca.h,textfilter and

private headers have been de-indented 1 tab and their documentation 
formatting have been made consistent

svn path=/trunk/kdesupport/qca/; revision=670321
This commit is contained in:
Justin Karneges 2007-06-01 03:00:13 +00:00
parent 24c38e3217
commit ff8b982fb6
6 changed files with 2305 additions and 2312 deletions

View File

@ -1,6 +1,6 @@
/* /*
* qca_core.h - Qt Cryptographic Architecture * qca_core.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com> * Copyright (C) 2003-2007 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net> * Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -59,10 +59,10 @@
QCA_EXPORT int qcaVersion(); QCA_EXPORT int qcaVersion();
/** /**
* QCA - the Qt Cryptographic Architecture QCA - the Qt Cryptographic Architecture
*/ */
namespace QCA namespace QCA {
{
class Provider; class Provider;
class Random; class Random;
class CertificateCollection; class CertificateCollection;
@ -74,29 +74,29 @@ namespace QCA
class Logger; class Logger;
/** /**
* Convenience representation for the plugin providers Convenience representation for the plugin providers
*
* You can get a list of providers using the providers() You can get a list of providers using the providers()
* function function
*
* \sa ProviderListIterator \sa ProviderListIterator
* \sa providers() \sa providers()
*/ */
typedef QList<Provider*> ProviderList; typedef QList<Provider*> ProviderList;
/** /**
* Mode settings for memory allocation Mode settings for memory allocation
*
* QCA can use secure memory, however most operating systems QCA can use secure memory, however most operating systems
* restrict the amount of memory that can be pinned by user restrict the amount of memory that can be pinned by user
* applications, to prevent a denial-of-service attack. applications, to prevent a denial-of-service attack.
*
* QCA supports two approaches to getting memory - the mlock QCA supports two approaches to getting memory - the mlock
* method, which generally requires root (administrator) level method, which generally requires root (administrator) level
* privileges, and the mmap method which is not as secure, but privileges, and the mmap method which is not as secure, but
* which should be able to be used by any process. which should be able to be used by any process.
*
* \sa Initializer \sa Initializer
*/ */
enum MemoryMode enum MemoryMode
{ {
@ -106,10 +106,10 @@ namespace QCA
}; };
/** /**
* Direction settings for symmetric algorithms Direction settings for symmetric algorithms
*
* For some algorithms, it makes sense to have a "direction", such For some algorithms, it makes sense to have a "direction", such
* as Cipher algorithms which can be used to encrypt or decrypt. as Cipher algorithms which can be used to encrypt or decrypt.
*/ */
enum Direction enum Direction
{ {
@ -118,77 +118,77 @@ namespace QCA
}; };
/** /**
* Initialise %QCA. Initialise %QCA.
* This call is not normally required, because it is cleaner This call is not normally required, because it is cleaner
* to use an Initializer. to use an Initializer.
*/ */
QCA_EXPORT void init(); QCA_EXPORT void init();
/** /**
* \overload \overload
*
* \param m the MemoryMode to use \param m the MemoryMode to use
* \param prealloc the amount of memory in kilobytes to allocate \param prealloc the amount of memory in kilobytes to allocate
* for secure storage for secure storage
*/ */
QCA_EXPORT void init(MemoryMode m, int prealloc); QCA_EXPORT void init(MemoryMode m, int prealloc);
/** /**
* Clean up routine Clean up routine
*
* This routine cleans up %QCA, including memory allocations This routine cleans up %QCA, including memory allocations
* This call is not normally required, because it is cleaner This call is not normally required, because it is cleaner
* to use an Initializer to use an Initializer
*/ */
QCA_EXPORT void deinit(); QCA_EXPORT void deinit();
/** /**
* Test if secure storage memory is available Test if secure storage memory is available
*
* \return true if secure storage memory is available \return true if secure storage memory is available
*/ */
QCA_EXPORT bool haveSecureMemory(); QCA_EXPORT bool haveSecureMemory();
/** /**
* Test if secure random is available Test if secure random is available
*
* Secure random is considered available if the global random Secure random is considered available if the global random
* provider is not the default provider. provider is not the default provider.
*
* \return true if secure random is available \return true if secure random is available
*/ */
QCA_EXPORT bool haveSecureRandom(); QCA_EXPORT bool haveSecureRandom();
/** /**
* Test if a capability (algorithm) is available. Test if a capability (algorithm) is available.
*
* Since capabilities are made available at runtime, you Since capabilities are made available at runtime, you
* should always check before using a capability the first should always check before using a capability the first
* time, as shown below. time, as shown below.
* \code \code
* QCA::init(); QCA::init();
* if(!QCA::isSupported("sha1")) if(!QCA::isSupported("sha1"))
* printf("SHA1 not supported!\n"); printf("SHA1 not supported!\n");
* else { else
* QString result = QCA::SHA1::hashToString(myString); {
* printf("sha1(\"%s\") = [%s]\n", myString.data(), qPrintable(result)); QString result = QCA::SHA1::hashToString(myString);
* } printf("sha1(\"%s\") = [%s]\n", myString.data(), qPrintable(result));
* \endcode }
* \endcode
* \param features the name of the capability to test for
* \param provider if specified, only check for the capability in that \param features the name of the capability to test for
\param provider if specified, only check for the capability in that
specific provider. If not provided, or provided as an empty specific provider. If not provided, or provided as an empty
string, then check for capabilities in all available providers string, then check for capabilities in all available providers
* \return true if the capability is available, otherwise false \return true if the capability is available, otherwise false
*
* Note that you can test for a combination of capabilities, Note that you can test for a combination of capabilities,
* using a comma delimited list: using a comma delimited list:
* \code \code
* QCA::isSupported("sha1,md5"): QCA::isSupported("sha1,md5"):
* \endcode \endcode
* which will return true if all of the capabilities listed which will return true if all of the capabilities listed
* are present. are present.
*
*/ */
QCA_EXPORT bool isSupported(const char *features, const QString &provider = QString()); QCA_EXPORT bool isSupported(const char *features, const QString &provider = QString());
@ -203,195 +203,192 @@ namespace QCA
QCA_EXPORT bool isSupported(const QStringList &features, const QString &provider = QString()); QCA_EXPORT bool isSupported(const QStringList &features, const QString &provider = QString());
/** /**
* Generate a list of all the supported features in plugins, Generate a list of all the supported features in plugins,
* and in built in capabilities and in built in capabilities
*
* \return a list containing the names of the features \return a list containing the names of the features
*
* The following code writes a list of features to standard out The following code writes a list of features to standard out
* \code \code
* QStringList capabilities; QStringList capabilities;
* capabilities = QCA::supportedFeatures(); capabilities = QCA::supportedFeatures();
* std::cout << "Supported:" << capabilities.join(",") << std::endl; std::cout << "Supported:" << capabilities.join(",") << std::endl;
* \endcode \endcode
* \sa isSupported(const char *features)
* \sa isSupported(const char *features) \sa isSupported(const QStringList &features)
* \sa isSupported(const QStringList &features) \sa defaultFeatures()
* \sa defaultFeatures()
*/ */
QCA_EXPORT QStringList supportedFeatures(); QCA_EXPORT QStringList supportedFeatures();
/** /**
* Generate a list of the built in features. This differs from Generate a list of the built in features. This differs from
* supportedFeatures() in that it does not include features provided supportedFeatures() in that it does not include features provided
* by plugins. by plugins.
*
* \return a list containing the names of the features \return a list containing the names of the features
*
* The following code writes a list of features to standard out The following code writes a list of features to standard out
* \code \code
* QStringList capabilities; QStringList capabilities;
* capabilities = QCA::defaultFeatures(); capabilities = QCA::defaultFeatures();
* std::cout << "Default:" << capabilities.join(",") << std::endl; std::cout << "Default:" << capabilities.join(",") << std::endl;
* \endcode \endcode
*
* \sa isSupported(const char *features) \sa isSupported
* \sa isSupported(const QStringList &features) \sa supportedFeatures()
* \sa supportedFeatures()
*/ */
QCA_EXPORT QStringList defaultFeatures(); QCA_EXPORT QStringList defaultFeatures();
/** /**
* Add a provider to the current list of providers Add a provider to the current list of providers
*
* This function allows you to add a provider to the This function allows you to add a provider to the
* current plugin providers at a specified priority. If current plugin providers at a specified priority. If
* a provider with the name already exists, this call fails. a provider with the name already exists, this call fails.
*
* \param p a pointer to a Provider object, which must be \param p a pointer to a Provider object, which must be
* set up. set up.
* \param priority the priority level to set the provider to \param priority the priority level to set the provider to
* \return true if the provider is added, and false if the
* \return true if the provider is added, and false if the provider is not added (failure)
* provider is not added (failure)
* \sa setProviderPriority for a description of the provider priority system
* \sa setProviderPriority for a description of the provider priority system
*/ */
QCA_EXPORT bool insertProvider(Provider *p, int priority = 0); QCA_EXPORT bool insertProvider(Provider *p, int priority = 0);
/** /**
* Change the priority of a specified provider Change the priority of a specified provider
*
* QCA supports a number of providers, and if a number of providers QCA supports a number of providers, and if a number of providers
* support the same algorithm, it needs to choose between them. You support the same algorithm, it needs to choose between them. You
* can do this at object instantiation time (by specifying the name can do this at object instantiation time (by specifying the name
* of the provider that should be used). Alternatively, you can provide a of the provider that should be used). Alternatively, you can provide a
* relative priority level at an application level, using this call. relative priority level at an application level, using this call.
*
* Priority is used at object instantiation time. The provider is selected Priority is used at object instantiation time. The provider is selected
* according to the following logic: according to the following logic:
* - if a particular provider is nominated, and that provider supports - if a particular provider is nominated, and that provider supports
* the required algorithm, then the nominated provider is used the required algorithm, then the nominated provider is used
* - if no provider is nominated, or it doesn't support the required - if no provider is nominated, or it doesn't support the required
* algorithm, then the provider with the lowest priority number will be used, algorithm, then the provider with the lowest priority number will be used,
* if that provider supports the algorithm. if that provider supports the algorithm.
* - if the provider with the lowest priority number doesn't support - if the provider with the lowest priority number doesn't support
* the required algorithm, the provider with the next lowest priority number the required algorithm, the provider with the next lowest priority number
* will be tried,and so on through to the provider with the largest priority number will be tried,and so on through to the provider with the largest priority number
* - if none of the plugin providers support the required algorithm, then - if none of the plugin providers support the required algorithm, then
* the default (built-in) provider will be tried. the default (built-in) provider will be tried.
*
* \param name the name of the provider \param name the name of the provider
* \param priority the new priority of the provider. As a special case, if \param priority the new priority of the provider. As a special case, if
* you pass in -1, then this provider gets the same priority as the you pass in -1, then this provider gets the same priority as the
* the last provider that was added or had its priority set using this the last provider that was added or had its priority set using this
* call. call.
*
* \sa providerPriority \sa providerPriority
*/ */
QCA_EXPORT void setProviderPriority(const QString &name, int priority); QCA_EXPORT void setProviderPriority(const QString &name, int priority);
/** /**
* Return the priority of a specified provider Return the priority of a specified provider
*
* The name of the provider (eg "qca-openssl") is used to look up the The name of the provider (eg "qca-openssl") is used to look up the
* current priority associated with that provider. If the provider current priority associated with that provider. If the provider
* is not found (or something else went wrong), -1 is returned. is not found (or something else went wrong), -1 is returned.
*
* \param name the name of the provider \param name the name of the provider
*
* \return the current priority level \return the current priority level
*
* \sa setProviderPriority for a description of the provider priority system \sa setProviderPriority for a description of the provider priority system
*/ */
QCA_EXPORT int providerPriority(const QString &name); QCA_EXPORT int providerPriority(const QString &name);
/** /**
* Return a list of the current providers Return a list of the current providers
*
* The current plugin providers are provided as a list, which you The current plugin providers are provided as a list, which you
* can iterate over using ProviderListIterator. can iterate over using ProviderListIterator.
*
* \sa ProviderList \sa ProviderList
* \sa ProviderListIterator \sa ProviderListIterator
*/ */
QCA_EXPORT ProviderList providers(); QCA_EXPORT ProviderList providers();
/** /**
* Return the named provider, or 0 if not found Return the named provider, or 0 if not found
*/ */
QCA_EXPORT Provider *findProvider(const QString &name); QCA_EXPORT Provider *findProvider(const QString &name);
/** /**
* Return the default provider Return the default provider
*/ */
QCA_EXPORT Provider *defaultProvider(); QCA_EXPORT Provider *defaultProvider();
/** /**
* Scan for new plugins Scan for new plugins
*/ */
QCA_EXPORT void scanForPlugins(); QCA_EXPORT void scanForPlugins();
/** /**
* Unload the current plugins Unload the current plugins
*/ */
QCA_EXPORT void unloadAllPlugins(); QCA_EXPORT void unloadAllPlugins();
/** /**
* Retrieve plugin diagnostic text Retrieve plugin diagnostic text
*/ */
QCA_EXPORT QString pluginDiagnosticText(); QCA_EXPORT QString pluginDiagnosticText();
/** /**
* Clear plugin diagnostic text Clear plugin diagnostic text
*/ */
QCA_EXPORT void clearPluginDiagnosticText(); QCA_EXPORT void clearPluginDiagnosticText();
/** /**
* Add plugin diagnostic text Add plugin diagnostic text
*
* This function should only be called by providers. This function should only be called by providers.
*/ */
QCA_EXPORT void appendPluginDiagnosticText(const QString &text); QCA_EXPORT void appendPluginDiagnosticText(const QString &text);
/** /**
* Set a global property Set a global property
*/ */
QCA_EXPORT void setProperty(const QString &name, const QVariant &value); QCA_EXPORT void setProperty(const QString &name, const QVariant &value);
/** /**
* Retrieve a global property Retrieve a global property
*/ */
QCA_EXPORT QVariant getProperty(const QString &name); QCA_EXPORT QVariant getProperty(const QString &name);
/** /**
* Set provider configuration Set provider configuration
*
* Allowed value types: QString, int, bool Allowed value types: QString, int, bool
*/ */
QCA_EXPORT void setProviderConfig(const QString &name, const QVariantMap &config); QCA_EXPORT void setProviderConfig(const QString &name, const QVariantMap &config);
/** /**
* Retrieve provider configuration Retrieve provider configuration
*/ */
QCA_EXPORT QVariantMap getProviderConfig(const QString &name); QCA_EXPORT QVariantMap getProviderConfig(const QString &name);
/** /**
* Save provider configuration to persistent storage Save provider configuration to persistent storage
*/ */
QCA_EXPORT void saveProviderConfig(const QString &name); QCA_EXPORT void saveProviderConfig(const QString &name);
/** /**
* Return the name of the global random number provider Return the name of the global random number provider
*/ */
QCA_EXPORT QString globalRandomProvider(); QCA_EXPORT QString globalRandomProvider();
/** /**
* Change the global random number provider Change the global random number provider
*
* The Random capabilities of %QCA are provided as part of the The Random capabilities of %QCA are provided as part of the
* built in capabilities, however the generator can be changed built in capabilities, however the generator can be changed
* if required. if required.
*/ */
QCA_EXPORT void setGlobalRandomProvider(const QString &provider); QCA_EXPORT void setGlobalRandomProvider(const QString &provider);
@ -459,70 +456,71 @@ namespace QCA
QCA_EXPORT CertificateCollection systemStore(); QCA_EXPORT CertificateCollection systemStore();
/** /**
* Get the application name that will be used by SASL server mode Get the application name that will be used by SASL server mode
*
* The application name is used by SASL in server mode, as some systems might The application name is used by SASL in server mode, as some systems might
* have different security policies depending on the app. have different security policies depending on the app.
* The default application name is 'qca' The default application name is 'qca'
*/ */
QCA_EXPORT QString appName(); QCA_EXPORT QString appName();
/** /**
* Set the application name that will be used by SASL server mode Set the application name that will be used by SASL server mode
*
* The application name is used by SASL in server mode, as some systems might The application name is used by SASL in server mode, as some systems might
* have different security policies depending on the app. This should be set have different security policies depending on the app. This should be set
* before using SASL objects, and it cannot be changed later. before using SASL objects, and it cannot be changed later.
*
* \param name the name string to use for SASL server mode \param name the name string to use for SASL server mode
*/ */
QCA_EXPORT void setAppName(const QString &name); QCA_EXPORT void setAppName(const QString &name);
/** /**
* Convert a byte array to printable hexadecimal Convert a byte array to printable hexadecimal
* representation. representation.
*
* This is a convenience function to convert an arbitrary This is a convenience function to convert an arbitrary
* SecureArray to a printable representation. SecureArray to a printable representation.
*
* \code \code
* SecureArray test(10); SecureArray test(10);
* test.fill('a'); test.fill('a');
* // 0x61 is 'a' in ASCII // 0x61 is 'a' in ASCII
* if (QString("61616161616161616161") == QCA::arrayToHex(test) ) { if (QString("61616161616161616161") == QCA::arrayToHex(test) )
* printf ("arrayToHex passed\n"); {
* } printf ("arrayToHex passed\n");
* \endcode }
* \endcode
* \param array the array to be converted
* \return a printable representation \param array the array to be converted
\return a printable representation
*/ */
QCA_EXPORT QString arrayToHex(const SecureArray &array); QCA_EXPORT QString arrayToHex(const SecureArray &array);
/** /**
* Convert a QString containing a hexadecimal representation Convert a QString containing a hexadecimal representation
* of a byte array into a QByteArray of a byte array into a QByteArray
*
* This is a convenience function to convert a printable This is a convenience function to convert a printable
* representation into a QByteArray - effectively the inverse representation into a QByteArray - effectively the inverse
* of QCA::arrayToHex. of QCA::arrayToHex.
*
* \code \code
* QCA::init(); QCA::init();
* QByteArray test(10); QByteArray test(10);
*
* test.fill('b'); // 0x62 in hexadecimal test.fill('b'); // 0x62 in hexadecimal
* test[7] = 0x00; // can handle strings with nulls test[7] = 0x00; // can handle strings with nulls
*
* if (QCA::hexToArray(QString("62626262626262006262") ) == test ) { if (QCA::hexToArray(QString("62626262626262006262") ) == test )
* printf ("hexToArray passed\n"); {
* } printf ("hexToArray passed\n");
* \endcode }
* \endcode
* \param hexString the string containing a printable
* representation to be converted \param hexString the string containing a printable
* \return the equivalent QByteArray representation to be converted
* \return the equivalent QByteArray
*/ */
QCA_EXPORT QByteArray hexToArray(const QString &hexString); QCA_EXPORT QByteArray hexToArray(const QString &hexString);
@ -539,11 +537,11 @@ namespace QCA
{ {
public: public:
/** /**
* Standard constructor Standard constructor
*
* \param m the MemoryMode to use for secure memory \param m the MemoryMode to use for secure memory
* \param prealloc the amount of secure memory to pre-allocate, \param prealloc the amount of secure memory to pre-allocate,
* in units of 1024 bytes (1K). in units of 1024 bytes (1K).
*/ */
explicit Initializer(MemoryMode m = Practical, int prealloc = 64); explicit Initializer(MemoryMode m = Practical, int prealloc = 64);
~Initializer(); ~Initializer();
@ -575,32 +573,32 @@ namespace QCA
{ {
public: public:
/** /**
* Construct a %KeyLength object Construct a %KeyLength object
*
* \param min the minimum length of the key, in bytes \param min the minimum length of the key, in bytes
* \param max the maximum length of the key, in bytes \param max the maximum length of the key, in bytes
* \param multiple the number of bytes that the key must be a \param multiple the number of bytes that the key must be a
* multiple of. multiple of.
*/ */
KeyLength(int min, int max, int multiple) KeyLength(int min, int max, int multiple)
: _min( min ), _max(max), _multiple( multiple ) : _min( min ), _max(max), _multiple( multiple )
{ } { }
/** /**
* Obtain the minimum length for the key, in bytes Obtain the minimum length for the key, in bytes
*/ */
int minimum() const { return _min; } int minimum() const { return _min; }
/** /**
* Obtain the maximum length for the key, in bytes Obtain the maximum length for the key, in bytes
*/ */
int maximum() const { return _max; } int maximum() const { return _max; }
/** /**
* Return the number of bytes that the key must be a multiple of Return the number of bytes that the key must be a multiple of
*
* If this is one, then anything between minimum and maximum (inclusive) If this is one, then anything between minimum and maximum (inclusive)
* is acceptable. is acceptable.
*/ */
int multiple() const { return _multiple; } int multiple() const { return _multiple; }
@ -629,99 +627,99 @@ namespace QCA
class Context; class Context;
/** /**
* Initialisation routine. Initialisation routine.
*
* This routine will be called when your plugin This routine will be called when your plugin
* is loaded, so this is a good place to do any is loaded, so this is a good place to do any
* one-off initialisation tasks. If you don't need one-off initialisation tasks. If you don't need
* any initialisation, just implement it as an empty any initialisation, just implement it as an empty
* routine. routine.
*/ */
virtual void init(); virtual void init();
/** /**
* Target QCA version for the provider. Target QCA version for the provider.
*
* This is used to verify compatibility between the This is used to verify compatibility between the
* provider and QCA. For a provider to be used, it provider and QCA. For a provider to be used, it
* must have major and minor version numbers that are must have major and minor version numbers that are
* less-than or equal to the QCA version (the patch less-than or equal to the QCA version (the patch
* version number is ignored). This means an older version number is ignored). This means an older
* provider may be used with a newer QCA, but a newer provider may be used with a newer QCA, but a newer
* provider cannot be used with an older QCA. provider cannot be used with an older QCA.
*/ */
virtual int version() const = 0; virtual int version() const = 0;
/** /**
* The name of the provider. The name of the provider.
*
* Typically you just return a string containing a Typically you just return a string containing a
* convenient name. convenient name.
*
* \code \code
* QString name() const QString name() const
* { {
* return "qca-myplugin"; return "qca-myplugin";
* } }
* \endcode \endcode
*
* \note The name is used to tell if a provider is \note The name is used to tell if a provider is
* already loaded, so you need to make sure it is already loaded, so you need to make sure it is
* unique amongst the various plugins. unique amongst the various plugins.
*/ */
virtual QString name() const = 0; virtual QString name() const = 0;
/** /**
* The capabilities (algorithms) of the provider. The capabilities (algorithms) of the provider.
*
* Typically you just return a fixed QStringList: Typically you just return a fixed QStringList:
* \code \code
* QStringList features() const QStringList features() const
* { {
* QStringList list; QStringList list;
* list += "sha1"; list += "sha1";
* list += "sha256"; list += "sha256";
* list += "hmac(md5)"; list += "hmac(md5)";
* return list; return list;
* } }
* \endcode \endcode
*/ */
virtual QStringList features() const = 0; virtual QStringList features() const = 0;
/** /**
* Optional credit text for the provider. Optional credit text for the provider.
*
* You might display this information in a credits or You might display this information in a credits or
* "About" dialog. Returns an empty string if the "About" dialog. Returns an empty string if the
* provider has no credit text. provider has no credit text.
*/ */
virtual QString credit() const; virtual QString credit() const;
/** /**
* Routine to create a plugin context Routine to create a plugin context
*
* You need to return a pointer to an algorithm You need to return a pointer to an algorithm
* Context that corresponds with the algorithm Context that corresponds with the algorithm
* name specified. name specified.
*
* \param type the name of the algorithm required \param type the name of the algorithm required
*
* \code \code
* Context *createContext(const QString &type) Context *createContext(const QString &type)
* { {
* if ( type == "sha1" ) if ( type == "sha1" )
* return new SHA1Context( this ); return new SHA1Context( this );
* else if ( type == "sha256" ) else if ( type == "sha256" )
* return new SHA0256Context( this ); return new SHA0256Context( this );
* else if ( type == "hmac(sha1)" ) else if ( type == "hmac(sha1)" )
* return new HMACSHA1Context( this ); return new HMACSHA1Context( this );
* else else
* return 0; return 0;
* } }
* \endcode \endcode
*
* Naturally you also need to implement Naturally you also need to implement
* the specified Context subclasses as well. the specified Context subclasses as well.
*/ */
virtual Context *createContext(const QString &type) = 0; virtual Context *createContext(const QString &type) = 0;
@ -1021,38 +1019,37 @@ namespace QCA
{ {
public: public:
/** /**
* Construct an empty (zero length) key Construct an empty (zero length) key
*/ */
SymmetricKey(); SymmetricKey();
/** /**
* Construct an key of specified size, with random contents Construct an key of specified size, with random contents
*
* This is intended to be used as a random session key. This is intended to be used as a random session key.
*
* \param size the number of bytes for the key \param size the number of bytes for the key
*
*/ */
SymmetricKey(int size); SymmetricKey(int size);
/** /**
* Construct a key from a provided byte array Construct a key from a provided byte array
*
* \param a the byte array to copy \param a the byte array to copy
*/ */
SymmetricKey(const SecureArray &a); SymmetricKey(const SecureArray &a);
/** /**
* Construct a key from a provided byte array Construct a key from a provided byte array
*
* \param a the byte array to copy \param a the byte array to copy
*/ */
SymmetricKey(const QByteArray &a); SymmetricKey(const QByteArray &a);
/** /**
* Test for weak DES keys Test for weak DES keys
*
* \return true if the key is a weak key for DES \return true if the key is a weak key for DES
*/ */
bool isWeakDESKey(); bool isWeakDESKey();
}; };
@ -1491,6 +1488,7 @@ namespace QCA
friend class Private; friend class Private;
Private *d; Private *d;
}; };
} }
#endif #endif

View File

@ -47,8 +47,8 @@
#include "qca_export.h" #include "qca_export.h"
#include "qca_tools.h" #include "qca_tools.h"
namespace QCA namespace QCA {
{
QCA_EXPORT QByteArray methodReturnType(const QMetaObject *obj, const QByteArray &method, const QList<QByteArray> argTypes); QCA_EXPORT QByteArray methodReturnType(const QMetaObject *obj, const QByteArray &method, const QList<QByteArray> argTypes);
QCA_EXPORT bool invokeMethodWithVariants(QObject *obj, const QByteArray &method, const QVariantList &args, QVariant *ret, Qt::ConnectionType type = Qt::AutoConnection); QCA_EXPORT bool invokeMethodWithVariants(QObject *obj, const QByteArray &method, const QVariantList &args, QVariant *ret, Qt::ConnectionType type = Qt::AutoConnection);
@ -371,9 +371,7 @@ namespace QCA
\return Current level \return Current level
*/ */
inline Logger::Severity level () const { inline Logger::Severity level () const { return m_logLevel; }
return m_logLevel;
}
/** /**
Set the current logging level Set the current logging level
@ -489,6 +487,7 @@ namespace QCA
QString m_name; QString m_name;
}; };
} }
#endif #endif

View File

@ -34,8 +34,8 @@
#include "qca_core.h" #include "qca_core.h"
namespace QCA namespace QCA {
{
/** /**
\class TextFilter qca_textfilter.h QtCrypto \class TextFilter qca_textfilter.h QtCrypto
@ -288,6 +288,7 @@ namespace QCA
bool _lb_enabled; bool _lb_enabled;
int _lb_column; int _lb_column;
}; };
} }
#endif #endif

View File

@ -87,199 +87,193 @@ namespace QCA {
cleared first. cleared first.
Note that this class is implicitly shared (that is, copy on write). Note that this class is implicitly shared (that is, copy on write).
**/ */
class QCA_EXPORT SecureArray class QCA_EXPORT SecureArray
{ {
public: public:
/** /**
* Construct a secure byte array, zero length Construct a secure byte array, zero length
*/ */
SecureArray(); SecureArray();
/** /**
* Construct a secure byte array of the specified length Construct a secure byte array of the specified length
*
* \param size the number of bytes in the array \param size the number of bytes in the array
* \param ch the value every byte should be set to \param ch the value every byte should be set to
*/ */
explicit SecureArray(int size, char ch = 0); explicit SecureArray(int size, char ch = 0);
/** /**
* Construct a secure byte array from a string Construct a secure byte array from a string
*
* Note that this copies, rather than references the source array Note that this copies, rather than references the source array
*/ */
SecureArray(const char *str); SecureArray(const char *str);
/** /**
* Construct a secure byte array from a QByteArray Construct a secure byte array from a QByteArray
*
* Note that this copies, rather than references the source array Note that this copies, rather than references the source array
*
* \sa operator=() \sa operator=()
*/ */
SecureArray(const QByteArray &a); SecureArray(const QByteArray &a);
/** /**
* Construct a (shallow) copy of another secure byte array Construct a (shallow) copy of another secure byte array
*
* \param from the source of the data and length. \param from the source of the data and length.
*/ */
SecureArray(const SecureArray &from); SecureArray(const SecureArray &from);
~SecureArray(); ~SecureArray();
/** /**
* Creates a reference, rather than a deep copy. Creates a reference, rather than a deep copy.
* if you want a deep copy then you should use copy()
* instead, or use operator=(), then call detach() when required.
*/ */
SecureArray & operator=(const SecureArray &from); SecureArray & operator=(const SecureArray &from);
/** /**
* Creates a copy, rather than references Creates a copy, rather than references
*
* \param a the array to copy from \param a the array to copy from
*/ */
SecureArray & operator=(const QByteArray &a); SecureArray & operator=(const QByteArray &a);
/** /**
* Clears the contents of the array and makes it empty Clears the contents of the array and makes it empty
*/ */
void clear(); void clear();
/** /**
* Returns a reference to the byte at the index position Returns a reference to the byte at the index position
*
* \param index the zero-based offset to obtain \param index the zero-based offset to obtain
*/ */
char & operator[](int index); char & operator[](int index);
/** /**
* Returns a reference to the byte at the index position Returns a reference to the byte at the index position
*
* \param index the zero-based offset to obtain \param index the zero-based offset to obtain
*/ */
const char & operator[](int index) const; const char & operator[](int index) const;
/** /**
* Pointer to the data in the secure array Pointer to the data in the secure array
*
* You can use this for memcpy and similar functions. If you are trying You can use this for memcpy and similar functions. If you are trying
* to obtain data at a particular offset, you might be better off using to obtain data at a particular offset, you might be better off using
* at() or operator[] at() or operator[]
*
*/ */
char *data(); char *data();
/** /**
* Pointer to the data in the secure array Pointer to the data in the secure array
*
* You can use this for memcpy and similar functions. If you are trying You can use this for memcpy and similar functions. If you are trying
* to obtain data at a particular offset, you might be better off using to obtain data at a particular offset, you might be better off using
* at() or operator[] at() or operator[]
*
*/ */
const char *data() const; const char *data() const;
/** /**
* Pointer to the data in the secure array Pointer to the data in the secure array
*
* You can use this for memcpy and similar functions. If you are trying You can use this for memcpy and similar functions. If you are trying
* to obtain data at a particular offset, you might be better off using to obtain data at a particular offset, you might be better off using
* at() or operator[] at() or operator[]
*
*/ */
const char *constData() const; const char *constData() const;
/** /**
* Returns a reference to the byte at the index position Returns a reference to the byte at the index position
*
* \param index the zero-based offset to obtain \param index the zero-based offset to obtain
*/ */
char & at(int index); char & at(int index);
/** /**
* Returns a reference to the byte at the index position Returns a reference to the byte at the index position
*
* \param index the zero-based offset to obtain \param index the zero-based offset to obtain
*/ */
const char & at(int index) const; const char & at(int index) const;
/** /**
* Returns the number of bytes in the array Returns the number of bytes in the array
*/ */
int size() const; int size() const;
/** /**
* Test if the array contains any bytes. Test if the array contains any bytes.
*
* This is equivalent to testing (size() != 0). Note that if This is equivalent to testing (size() != 0). Note that if
* the array is allocated, isEmpty() is false (even if no data the array is allocated, isEmpty() is false (even if no data
* has been added) has been added)
*
* \return true if the array has zero length, otherwise false \return true if the array has zero length, otherwise false
*/ */
bool isEmpty() const; bool isEmpty() const;
/** /**
* Change the length of this array Change the length of this array
* If the new length is less than the old length, the extra information If the new length is less than the old length, the extra information
* is (safely) discarded. If the new length is equal to or greater than is (safely) discarded. If the new length is equal to or greater than
* the old length, the existing data is copied into the array. the old length, the existing data is copied into the array.
*
* \param size the new length \param size the new length
*/ */
bool resize(int size); bool resize(int size);
/** /**
* Fill the data array with a specified character Fill the data array with a specified character
*
* \param fillChar the character to use as the fill \param fillChar the character to use as the fill
* \param fillToPosition the number of characters to fill \param fillToPosition the number of characters to fill
* to. If not specified (or -1), fills array to to. If not specified (or -1), fills array to
* current length. current length.
*
* \note This function does not extend the array - if \note This function does not extend the array - if
* you ask for fill beyond the current length, only you ask for fill beyond the current length, only
* the current length will be used. the current length will be used.
* \note The number of characters is 1 based, so if \note The number of characters is 1 based, so if
* you ask for fill('x', 10), it will fill from you ask for fill('x', 10), it will fill from
*
*/ */
void fill(char fillChar, int fillToPosition = -1); void fill(char fillChar, int fillToPosition = -1);
/** /**
* Copy the contents of the secure array out to a Copy the contents of the secure array out to a
* standard QByteArray. Note that this performs a deep copy standard QByteArray. Note that this performs a deep copy
* of the data. of the data.
*/ */
QByteArray toByteArray() const; QByteArray toByteArray() const;
/** /**
* Append a secure byte array to the end of this array Append a secure byte array to the end of this array
*/ */
SecureArray & append(const SecureArray &a); SecureArray & append(const SecureArray &a);
/** /**
* Append a secure byte array to the end of this array Append a secure byte array to the end of this array
*/ */
SecureArray & operator+=(const SecureArray &a); SecureArray & operator+=(const SecureArray &a);
protected: protected:
/** /**
* Assign the contents of a provided byte array to this Assign the contents of a provided byte array to this
* object. object.
*
* \param from the byte array to copy \param from the byte array to copy
*/ */
void set(const SecureArray &from); void set(const SecureArray &from);
/** /**
* Assign the contents of a provided byte array to this Assign the contents of a provided byte array to this
* object. object.
*
* \param from the byte array to copy \param from the byte array to copy
*/ */
void set(const QByteArray &from); void set(const QByteArray &from);
@ -289,27 +283,27 @@ private:
}; };
/** /**
* Equality operator. Returns true if the two SecureArray Equality operator. Returns true if the two SecureArray
* arguments have the same data (and the same length, of course). arguments have the same data (and the same length, of course).
*
* \relates SecureArray \relates SecureArray
**/ */
QCA_EXPORT bool operator==(const SecureArray &a, const SecureArray &b); QCA_EXPORT bool operator==(const SecureArray &a, const SecureArray &b);
/** /**
* Inequality operator. Returns true if the two SecureArray Inequality operator. Returns true if the two SecureArray
* arguments have different length, or the same length but arguments have different length, or the same length but
* different data different data
*
* \relates SecureArray \relates SecureArray
**/ */
QCA_EXPORT bool operator!=(const SecureArray &a, const SecureArray &b); QCA_EXPORT bool operator!=(const SecureArray &a, const SecureArray &b);
/** /**
* Returns an array that is the result of concatenating a and b Returns an array that is the result of concatenating a and b
*
* \relates SecureArray \relates SecureArray
**/ */
QCA_EXPORT const SecureArray operator+(const SecureArray &a, const SecureArray &b); QCA_EXPORT const SecureArray operator+(const SecureArray &a, const SecureArray &b);
/** /**
@ -325,178 +319,177 @@ QCA_EXPORT const SecureArray operator+(const SecureArray &a, const SecureArray &
// do something // do something
} }
\endcode \endcode
**/ */
class QCA_EXPORT BigInteger class QCA_EXPORT BigInteger
{ {
public: public:
/** /**
* Constructor. Creates a new BigInteger, initialised to zero. Constructor. Creates a new BigInteger, initialised to zero.
*/ */
BigInteger(); BigInteger();
/** /**
* \overload \overload
*
* \param n an alternative integer initialisation value. \param n an alternative integer initialisation value.
*/ */
BigInteger(int n); BigInteger(int n);
/** /**
* \overload \overload
*
* \param c an alternative initialisation value, encoded as a character array \param c an alternative initialisation value, encoded as a character array
*
* \code \code
* BigInteger b ( "9890343" ); BigInteger b ( "9890343" );
* \endcode \endcode
*/ */
BigInteger(const char *c); BigInteger(const char *c);
/** /**
* \overload \overload
*
* \param s an alternative initialisation value, encoded as a string \param s an alternative initialisation value, encoded as a string
*/ */
BigInteger(const QString &s); BigInteger(const QString &s);
/** /**
* \overload \overload
*
* \param a an alternative initialisation value, encoded as SecureArray \param a an alternative initialisation value, encoded as SecureArray
*/ */
BigInteger(const QCA::SecureArray &a); BigInteger(const QCA::SecureArray &a);
/** /**
* \overload \overload
*
* \param from an alternative initialisation value, encoded as a %BigInteger \param from an alternative initialisation value, encoded as a %BigInteger
*/ */
BigInteger(const BigInteger &from); BigInteger(const BigInteger &from);
~BigInteger(); ~BigInteger();
/** /**
* Assignment operator Assignment operator
*
* \param from the BigInteger to copy from \param from the BigInteger to copy from
*
* \code \code
* BigInteger a; // a is zero BigInteger a; // a is zero
* BigInteger b( 500 ); BigInteger b( 500 );
* a = b; // a is now 500 a = b; // a is now 500
* \endcode \endcode
*/ */
BigInteger & operator=(const BigInteger &from); BigInteger & operator=(const BigInteger &from);
/** /**
* \overload \overload
*
* \param s the QString containing an integer representation \param s the QString containing an integer representation
*
* \sa bool fromString(const QString &s) \sa bool fromString(const QString &s)
*
* \note it is the application's responsibility to make sure \note it is the application's responsibility to make sure
* that the QString represents a valid integer (ie it only that the QString represents a valid integer (ie it only
* contains numbers and an optional minus sign at the start) contains numbers and an optional minus sign at the start)
* */
**/
BigInteger & operator=(const QString &s); BigInteger & operator=(const QString &s);
/** /**
* Increment in place operator Increment in place operator
*
* \param b the amount to increment by \param b the amount to increment by
*
* \code \code
* BigInteger a; // a is zero BigInteger a; // a is zero
* BigInteger b( 500 ); BigInteger b( 500 );
* a += b; // a is now 500 a += b; // a is now 500
* a += b; // a is now 1000 a += b; // a is now 1000
* \endcode \endcode
**/ */
BigInteger & operator+=(const BigInteger &b); BigInteger & operator+=(const BigInteger &b);
/** /**
* Decrement in place operator Decrement in place operator
*
* \param b the amount to decrement by \param b the amount to decrement by
*
* \code \code
* BigInteger a; // a is zero BigInteger a; // a is zero
* BigInteger b( 500 ); BigInteger b( 500 );
* a -= b; // a is now -500 a -= b; // a is now -500
* a -= b; // a is now -1000 a -= b; // a is now -1000
* \endcode \endcode
**/ */
BigInteger & operator-=(const BigInteger &b); BigInteger & operator-=(const BigInteger &b);
/** /**
* Output %BigInteger as a byte array, useful for storage or Output %BigInteger as a byte array, useful for storage or
* transmission. The format is a binary integer in sign-extended transmission. The format is a binary integer in sign-extended
* network-byte-order. network-byte-order.
*
* \sa void fromArray(const SecureArray &a); \sa void fromArray(const SecureArray &a);
*/ */
QCA::SecureArray toArray() const; QCA::SecureArray toArray() const;
/** /**
* Assign from an array. The input is expected to be a binary integer Assign from an array. The input is expected to be a binary integer
* in sign-extended network-byte-order. in sign-extended network-byte-order.
*
* \param a a SecureArray that represents an integer \param a a SecureArray that represents an integer
*
* \sa BigInteger(const SecureArray &a); \sa BigInteger(const SecureArray &a);
* \sa SecureArray toArray() const; \sa SecureArray toArray() const;
*/ */
void fromArray(const QCA::SecureArray &a); void fromArray(const QCA::SecureArray &a);
/** /**
* Convert %BigInteger to a QString Convert %BigInteger to a QString
*
* \code \code
* QString aString; QString aString;
* BigInteger aBiggishInteger( 5878990 ); BigInteger aBiggishInteger( 5878990 );
* aString = aBiggishInteger.toString(); // aString is now "5878990" aString = aBiggishInteger.toString(); // aString is now "5878990"
* \endcode \endcode
*/ */
QString toString() const; QString toString() const;
/** /**
* Assign from a QString Assign from a QString
*
* \param s a QString that represents an integer \param s a QString that represents an integer
*
* \note it is the application's responsibility to make sure \note it is the application's responsibility to make sure
* that the QString represents a valid integer (ie it only that the QString represents a valid integer (ie it only
* contains numbers and an optional minus sign at the start) contains numbers and an optional minus sign at the start)
*
* \sa BigInteger(const QString &s) \sa BigInteger(const QString &s)
* \sa BigInteger & operator=(const QString &s) \sa BigInteger & operator=(const QString &s)
*/ */
bool fromString(const QString &s); bool fromString(const QString &s);
/** /**
* Compare this value with another %BigInteger Compare this value with another %BigInteger
*
* Normally it is more readable to use one of the operator overloads, Normally it is more readable to use one of the operator overloads,
* so you don't need to use this method directly. so you don't need to use this method directly.
*
* \param n the BigInteger to compare with \param n the BigInteger to compare with
*
* \return zero if the values are the same, negative if the argument \return zero if the values are the same, negative if the argument
* is less than the value of this BigInteger, and positive if the argument is less than the value of this BigInteger, and positive if the argument
* value is greater than this BigInteger value is greater than this BigInteger
*
* \code \code
* BigInteger a( "400" ); BigInteger a( "400" );
* BigInteger b( "-400" ); BigInteger b( "-400" );
* BigInteger c( " 200 " ); BigInteger c( " 200 " );
* int result; int result;
* result = a.compare( b ); // return positive 400 > -400 result = a.compare( b ); // return positive 400 > -400
* result = a.compare( c ); // return positive, 400 > 200 result = a.compare( c ); // return positive, 400 > 200
* result = b.compare( c ); // return negative, -400 < 200 result = b.compare( c ); // return negative, -400 < 200
* \endcode \endcode
**/ */
int compare(const BigInteger &n) const; int compare(const BigInteger &n) const;
private: private:
@ -505,80 +498,80 @@ private:
}; };
/** /**
* Equality operator. Returns true if the two BigInteger values Equality operator. Returns true if the two BigInteger values
* are the same, including having the same sign. are the same, including having the same sign
*
* \relates BigInteger \relates BigInteger
**/ */
inline bool operator==(const BigInteger &a, const BigInteger &b) inline bool operator==(const BigInteger &a, const BigInteger &b)
{ {
return (0 == a.compare( b ) ); return (0 == a.compare( b ) );
} }
/** /**
* Inequality operator. Returns true if the two BigInteger values Inequality operator. Returns true if the two BigInteger values
* are different in magnitude, sign or both are different in magnitude, sign or both
*
* \relates BigInteger \relates BigInteger
**/ */
inline bool operator!=(const BigInteger &a, const BigInteger &b) inline bool operator!=(const BigInteger &a, const BigInteger &b)
{ {
return (0 != a.compare( b ) ); return (0 != a.compare( b ) );
} }
/** /**
* Less than or equal operator. Returns true if the BigInteger value Less than or equal operator. Returns true if the BigInteger value
* on the left hand side is equal to or less than the BigInteger value on the left hand side is equal to or less than the BigInteger value
* on the right hand side. on the right hand side.
*
* \relates BigInteger \relates BigInteger
**/ */
inline bool operator<=(const BigInteger &a, const BigInteger &b) inline bool operator<=(const BigInteger &a, const BigInteger &b)
{ {
return (a.compare( b ) <= 0 ); return (a.compare( b ) <= 0 );
} }
/** /**
* Greater than or equal operator. Returns true if the BigInteger value Greater than or equal operator. Returns true if the BigInteger value
* on the left hand side is equal to or greater than the BigInteger value on the left hand side is equal to or greater than the BigInteger value
* on the right hand side. on the right hand side.
*
* \relates BigInteger \relates BigInteger
**/ */
inline bool operator>=(const BigInteger &a, const BigInteger &b) inline bool operator>=(const BigInteger &a, const BigInteger &b)
{ {
return (a.compare( b ) >= 0 ); return (a.compare( b ) >= 0 );
} }
/** /**
* Less than operator. Returns true if the BigInteger value Less than operator. Returns true if the BigInteger value
* on the left hand side is less than the BigInteger value on the left hand side is less than the BigInteger value
* on the right hand side. on the right hand side.
*
* \relates BigInteger \relates BigInteger
**/ */
inline bool operator<(const BigInteger &a, const BigInteger &b) inline bool operator<(const BigInteger &a, const BigInteger &b)
{ {
return (a.compare( b ) < 0 ); return (a.compare( b ) < 0 );
} }
/** /**
* Greater than operator. Returns true if the BigInteger value Greater than operator. Returns true if the BigInteger value
* on the left hand side is greater than the BigInteger value on the left hand side is greater than the BigInteger value
* on the right hand side. on the right hand side.
*
* \relates BigInteger \relates BigInteger
**/ */
inline bool operator>(const BigInteger &a, const BigInteger &b) inline bool operator>(const BigInteger &a, const BigInteger &b)
{ {
return (a.compare( b ) > 0 ); return (a.compare( b ) > 0 );
} }
/** /**
* Stream operator. Stream operator
*
* \relates BigInteger \relates BigInteger
**/ */
QCA_EXPORT QTextStream &operator<<(QTextStream &stream, const BigInteger &b); QCA_EXPORT QTextStream &operator<<(QTextStream &stream, const BigInteger &b);
} }

View File

@ -27,8 +27,8 @@
#include "qca_core.h" #include "qca_core.h"
#include <QMutex> #include <QMutex>
namespace QCA namespace QCA {
{
class ProviderItem; class ProviderItem;
class ProviderManager class ProviderManager
@ -66,6 +66,7 @@ namespace QCA
void addItem(ProviderItem *i, int priority); void addItem(ProviderItem *i, int priority);
bool haveAlready(const QString &name) const; bool haveAlready(const QString &name) const;
}; };
} }
#endif #endif

View File

@ -25,10 +25,11 @@
#include "qca_cert.h" #include "qca_cert.h"
namespace QCA namespace QCA {
{
bool qca_have_systemstore(); bool qca_have_systemstore();
CertificateCollection qca_get_systemstore(const QString &provider); CertificateCollection qca_get_systemstore(const QString &provider);
} }
#endif #endif