<commit_before>/*
 * qca.h - Qt Cryptographic Architecture
 * Copyright (C) 2003,2004  <NAME>
 * Copyright (C) 2004  <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef QCA_H
#define QCA_H

#include <qstring.h>
#include <qcstring.h>
#include <qdatetime.h>
#include <qmap.h>
#include <qptrlist.h>
#include <qobject.h>
#include <qtextstream.h>

#ifdef Q_OS_WIN32
# ifndef QCA_STATIC
#  ifdef QCA_MAKEDLL
#   define QCA_EXPORT __declspec(dllexport)
#  else
#   define QCA_EXPORT __declspec(dllimport)
#  endif
# endif
#endif
#ifndef QCA_EXPORT
# define QCA_EXPORT
#endif

#ifdef Q_OS_WIN32
# ifdef QCA_PLUGIN_DLL
#  define QCA_PLUGIN_EXPORT extern "C" __declspec(dllexport)
# else
#  define QCA_PLUGIN_EXPORT extern "C" __declspec(dllimport)
# endif
#endif
#ifndef QCA_PLUGIN_EXPORT
# define QCA_PLUGIN_EXPORT extern "C"
#endif

class QHostAddress;
class QStringList;

class QCAProvider;
class QCA_HashContext;
class QCA_CipherContext;
class QCA_CertContext;

/**
 * \mainpage Qt Cryptographic Architecture
 *
 * This library provides an easy API for the following features:
 *   - SSL/TLS
 *   - X509 certificate (Cert)
 *   - Simple Authentication and Security Layer (SASL)
 *   - RSA
 *   - Hashing 
 *       - SHA0
 *       - SHA1
 *       - MD2
 *       - MD4
 *       - MD5
 *       - RIPEMD160
 *   - Ciphers
 *       - BlowFish
 *       - TripleDES
 *       - AES (AES128, AES256)
 *
 * Functionality is supplied via plugins.  This is useful for avoiding
 * dependence on a particular crypto library and makes upgrading easier,
 * as there is no need to recompile your application when adding or
 * upgrading a crypto plugin.  Also, by pushing crypto functionality into
 * plugins, your application is free of legal issues, such as export
 * regulation.
 *
 * And of course, you get a very simple crypto API for Qt, where you can
 * do things like:
 * \code
 * QString hash = QCA::SHA1().hashToString(blockOfData);
 * \endcode
 */

// Direct secure memory access.  For interfacing with C libraries if needed.
QCA_EXPORT void *qca_secure_alloc(int bytes);
QCA_EXPORT void qca_secure_free(void *p);

/**
 * Secure array of bytes
 *
 * The %QSecureArray provides an array of memory from a pool that is, 
 * at least partly, secure. In this sense, secure means that the contents
 * of the memory should not be made available to other applications. By
 * comparison, a QMemArray (or subclass such as QCString or QByteArray) may
 * be held in pages that are free'd without being cleared first. This means
 * that a malicious application can just repeatedly request pages of memory,
 * searching for something that could be of value.
 **/ 
QCA_EXPORT class QSecureArray
{
public:
	/**
	 * Construct a secure byte array, zero length
	 */
	QSecureArray();

	/**
	 * Construct a secure byte array of the specified length
	 *
	 * \param size the number of bytes in the array
	 */
	QSecureArray(int size);

	/**
	 * Construct a secure byte array from a QByteArray
	 *
	 * Note that this copies, rather than references the source array
	 *
	 * \sa operator=
	 */
	QSecureArray(const QByteArray &a);

	QSecureArray(const QSecureArray &from);

	~QSecureArray();

	/** 
	 * creates a reference, rather than a copy.
	 * if you want a copy, call detach()
	 */
	QSecureArray & operator=(const QSecureArray &from);

	/**
	 * creates a copy, rather than references
	 */
	QSecureArray & operator=(const QByteArray &a);

	char & operator[](int index);

	const char & operator[](int index) const;

	char *data() const;

	const char & at(uint index) const;

	char & at(uint index);

	uint size() const;

	bool isEmpty() const;

	bool resize(uint size);

	QSecureArray copy() const;

	void detach();

	QByteArray toByteArray() const;

private:<commit_msg>Finishes off the API docs for QSecureArray<commit_after>/*
 * qca.h - Qt Cryptographic Architecture
 * Copyright (C) 2003,2004  <NAME>
 * Copyright (C) 2004  <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef QCA_H
#define QCA_H

#include <qstring.h>
#include <qcstring.h>
#include <qdatetime.h>
#include <qmap.h>
#include <qptrlist.h>
#include <qobject.h>
#include <qtextstream.h>

#ifdef Q_OS_WIN32
# ifndef QCA_STATIC
#  ifdef QCA_MAKEDLL
#   define QCA_EXPORT __declspec(dllexport)
#  else
#   define QCA_EXPORT __declspec(dllimport)
#  endif
# endif
#endif
#ifndef QCA_EXPORT
# define QCA_EXPORT
#endif

#ifdef Q_OS_WIN32
# ifdef QCA_PLUGIN_DLL
#  define QCA_PLUGIN_EXPORT extern "C" __declspec(dllexport)
# else
#  define QCA_PLUGIN_EXPORT extern "C" __declspec(dllimport)
# endif
#endif
#ifndef QCA_PLUGIN_EXPORT
# define QCA_PLUGIN_EXPORT extern "C"
#endif

class QHostAddress;
class QStringList;

class QCAProvider;
class QCA_HashContext;
class QCA_CipherContext;
class QCA_CertContext;

/**
 * \mainpage Qt Cryptographic Architecture
 *
 * This library provides an easy API for the following features:
 *   - SSL/TLS
 *   - X509 certificate (Cert)
 *   - Simple Authentication and Security Layer (SASL)
 *   - RSA
 *   - Hashing 
 *       - SHA0
 *       - SHA1
 *       - MD2
 *       - MD4
 *       - MD5
 *       - RIPEMD160
 *   - Ciphers
 *       - BlowFish
 *       - TripleDES
 *       - AES (AES128, AES256)
 *
 * Functionality is supplied via plugins.  This is useful for avoiding
 * dependence on a particular crypto library and makes upgrading easier,
 * as there is no need to recompile your application when adding or
 * upgrading a crypto plugin.  Also, by pushing crypto functionality into
 * plugins, your application is free of legal issues, such as export
 * regulation.
 *
 * And of course, you get a very simple crypto API for Qt, where you can
 * do things like:
 * \code
 * QString hash = QCA::SHA1().hashToString(blockOfData);
 * \endcode
 */

// Direct secure memory access.  For interfacing with C libraries if needed.
QCA_EXPORT void *qca_secure_alloc(int bytes);
QCA_EXPORT void qca_secure_free(void *p);

/**
 * Secure array of bytes
 *
 * The %QSecureArray provides an array of memory from a pool that is, 
 * at least partly, secure. In this sense, secure means that the contents
 * of the memory should not be made available to other applications. By
 * comparison, a QMemArray (or subclass such as QCString or QByteArray) may
 * be held in pages that are free'd without being cleared first. This means
 * that a malicious application can just repeatedly request pages of memory,
 * searching for something that could be of value.
 *
 * Note that this class is implicitly shared (that is, copy on write).
 **/ 
QCA_EXPORT class QSecureArray
{
public:
	/**
	 * Construct a secure byte array, zero length
	 */
	QSecureArray();

	/**
	 * Construct a secure byte array of the specified length
	 *
	 * \param size the number of bytes in the array
	 */
	QSecureArray(int size);

	/**
	 * Construct a secure byte array from a QByteArray
	 *
	 * Note that this copies, rather than references the source array
	 *
	 * \sa operator=()
	 */
	QSecureArray(const QByteArray &a);

	/**
	 * Construct a (shallow) copy of another secure byte array
	 *
	 * \param from the source of the data and length.
	 */
	QSecureArray(const QSecureArray &from);

	~QSecureArray();

	/** 
	 * 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.
	 */
	QSecureArray & operator=(const QSecureArray &from);

	/**
	 * Creates a copy, rather than references
	 *
	 * \param a the array to copy from
	 */
	QSecureArray & operator=(const QByteArray &a);

	/**
	 * Returns a reference to the byte at the index position
	 *
	 * \param index the zero-based offset to obtain
	 */
	char & operator[](int index);

	/**
	 * Returns a reference to the byte at the index position
	 *
	 * \param index the zero-based offset to obtain
	 */
	const char & operator[](int index) const;

	/**
	 * Pointer the data in the secure array
	 * 
	 * 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
	 * at() or operator[]
	 *
	 */
	char *data() const;

	/**
	 * Returns a reference to the byte at the index position
	 *
	 * \param index the zero-based offset to obtain
	 */
	const char & at(uint index) const;

	/**
	 * Returns a reference to the byte at the index position
	 *
	 * \param index the zero-based offset to obtain
	 */
	char & at(uint index);

	/**
	 * Return the number of bytes in the array
	 */
	uint size() const;

	/**
	 * Test if the array contains any bytes.
	 * 
	 * This is equivalent to testing (size() != 0). Note that if
	 * the array is allocated, isEmpty() is false (even if no data
	 * has been added)
	 *
	 * \return true if the array has zero length, otherwise false
	 */
	bool isEmpty() const;

	/**
	 * Change the length of this array
	 * 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
	 * the old length, the existing data is copied into the array.
	 *
	 * \param size the new length
	 */
	bool resize(uint size);

	/** 
	 * creates a deep copy, rather than a reference
	 * if you want a reference then you should use operator=()
	 */
	QSecureArray copy() const;

	/**
	 * If the current array is shared, this conducts a deep copy, 
	 * otherwise it has no effect.
	 *
	 * \code
	 * QSecureArray myArray = anotherArray; // currently the same
	 * myArray.detach(); // no longer the same data, but a copy
	 * // anything here that affects anotherArray does not affect
	 * // myArray; and vice versa.
	 * \endcode
	 */
	 void detach();

	 /**
	  * Copy the contents of the secure array out to a 
	  * standard QByteArray. Note that this performs a deep copy
	  * of the data.
	  */
	 QByteArray toByteArray() const;

private:
{'fraction_non_alphanumeric': 0.08489388264669163, 'fraction_numerical': 0.009006598894239343, 'mean_word_length': 3.355339805825243, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6378786', 'n_tokens_mistral': 3582, 'n_tokens_neox': 3275, 'n_words': 1434}