From e932e57c04a8e2af39624f1207c9411eb0e976db Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Jun 2021 21:33:43 +0000 Subject: [PATCH] No console --- include/QtCrypto/qca_support.h | 430 --------------------------------- src/CMakeLists.txt | 42 ++-- 2 files changed, 21 insertions(+), 451 deletions(-) diff --git a/include/QtCrypto/qca_support.h b/include/QtCrypto/qca_support.h index 8e46bb7..2de8830 100644 --- a/include/QtCrypto/qca_support.h +++ b/include/QtCrypto/qca_support.h @@ -497,436 +497,6 @@ private: Private *d; }; -class ConsolePrivate; -class ConsoleReferencePrivate; -class ConsoleReference; - -/** - \class Console qca_support.h QtCrypto - - %QCA %Console system - - %QCA provides an API for asynchronous, event-based access to - the console and stdin/stdout, as these facilities are - otherwise not portable. The primary use of this system within - %QCA is for passphrase prompting in command-line applications, - using the tty console type. - - How it works: Create a %Console object for the type of console - desired, and then use ConsoleReference to act on the console. - Only one ConsoleReference may operate on a %Console at a time. - - A %Console object takes over either the physical console (Console::Tty - type) or stdin/stdout (Console::Stdio type). Only one of each type - may be created at a time. - - Whenever code is written that needs a tty or stdio object, the - code should first call one of the static methods (ttyInstance() - or stdioInstance()) to see if a console object for the desired - type exists already. If the object exists, use it. If it does - not exist, the rule is that the relevant code should create the - object, use the object, and then destroy the object when the - operation is completed. - - By following the above rule, you can write code that utilizes - a console without the application having to create some master - console object for you. Of course, if the application has - created a console then it will be used. - - The reason why there is a master console object is that it - is not guaranteed that all I/O will survive creation and - destruction of a console object. If you are using the Stdio - Type, then you probably want a long-lived console object. It - is possible to capture unprocessed I/O by calling - bytesLeftToRead or bytesLeftToWrite. However, it is not - expected that general console-needing code will call these - functions when utilizing a temporary console. Thus, an - application developer would need to create his own console - object, invoke the console-needing code, and then do his own - extraction of the unprocessed I/O if necessary. Another reason - to extract unprocessed I/O is if you need to switch from - %Console back to standard functions (e.g. fgets() ). - - \ingroup UserAPI -*/ -class QCA_EXPORT Console : public QObject -{ - Q_OBJECT -public: - /** - The type of console object - */ - enum Type - { - Tty, ///< physical console - Stdio ///< stdin/stdout - }; - /** - The type of I/O to use with the console object. - */ - enum ChannelMode - { - Read, ///< Read only (equivalent to stdin) - ReadWrite ///< Read/write (equivalent to stdin and stdout) - }; - - /** - The nature of the console operation - */ - enum TerminalMode - { - Default, ///< use default terminal settings - Interactive ///< char-by-char input, no echo - }; - - /** - Standard constructor - - Note that library code should not create a new Console object - without checking whether there is already a Console object of - the required Type. See the main documentation for Console for the - rationale for this. - - \param type the Type of Console object to create - \param cmode the ChannelMode (I/O type) to use - \param tmode the TerminalMode to use - \param parent the parent object for this object - - \sa ttyInstance() and stdioInstance for static methods that allow - you to test whether there is already a Console object of the - required Type, and if there is, obtain a reference to that object. - */ - Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent = nullptr); - ~Console() override; - - /** - The Type of this Console object - */ - Type type() const; - - /** - The ChannelMode of this Console object - */ - ChannelMode channelMode() const; - - /** - The TerminalMode of this Console object - */ - TerminalMode terminalMode() const; - - /** - Test whether standard input is redirected. - - \sa type() and channelMode() - */ - static bool isStdinRedirected(); - - /** - Test whether standard output is redirected. - - \sa type() and channelMode() - */ - static bool isStdoutRedirected(); - - /** - The current terminal-type console object - - \return null if there is no current Console - of this type, otherwise the Console to use - */ - static Console *ttyInstance(); - - /** - The current stdio-type console object - - \return null if there is no current Console - of this type, otherwise the Console to use - */ - static Console *stdioInstance(); - - /** - Release the Console - - This allows access to buffers containing any remaining data - */ - void release(); - - /** - Obtain remaining data from the Console, awaiting - a read operation - */ - QByteArray bytesLeftToRead(); - - /** - Obtain remaining data from the Console, awaiting - a write operation - */ - QByteArray bytesLeftToWrite(); - -private: - Q_DISABLE_COPY(Console) - - friend class ConsolePrivate; - ConsolePrivate *d; - - friend class ConsoleReference; -}; - -/** - \class ConsoleReference qca_support.h QtCrypto - - Manager for a Console - - \note Only one %ConsoleReference object can be active at a time - - \ingroup UserAPI -*/ -class QCA_EXPORT ConsoleReference : public QObject -{ - Q_OBJECT -public: - /** - The security setting to use for the Console being managed. - */ - enum SecurityMode - { - SecurityDisabled, - SecurityEnabled - }; - - /** - Standard constructor - - \param parent the parent object for this object - */ - ConsoleReference(QObject *parent = nullptr); - ~ConsoleReference() override; - - /** - Set the Console object to be managed, and start processing. - - You typically want to use Console::ttyInstance() or - Console::stdioInstance() to obtain the required Console - reference. - - \param console reference to the Console to be managed - \param mode the SecurityMode to use for this Console. - - \sa QCA::Console for more information on how to handle the - console aspects of your application or library code. - */ - bool start(Console *console, SecurityMode mode = SecurityDisabled); - - /** - Stop processing, and release the Console - */ - void stop(); - - /** - The Console object managed by this object - - \sa start() to set the Console to be managed - */ - Console *console() const; - - /** - The security mode setting for the Console object - managed by this object. - - \sa start() to set the SecurityMode - */ - SecurityMode securityMode() const; - - /** - Read data from the Console. - - \param bytes the number of bytes to read. The default - is to read all available bytes - - \sa readSecure() for a method suitable for reading - sensitive data. - */ - QByteArray read(int bytes = -1); - - /** - Write data to the Console. - - \param a the array of data to write to the Console - - \sa writeSecure() for a method suitable for writing - sensitive data. - */ - void write(const QByteArray &a); - - /** - Read secure data from the Console - - \param bytes the number of bytes to read. The default - is to read all available bytes - - \sa read() which is suitable for non-sensitive data - */ - SecureArray readSecure(int bytes = -1); - - /** - Write secure data to the Console - - \param a the array of data to write to the Console - - \sa write() which is suitable for non-sensitive data - */ - void writeSecure(const SecureArray &a); - - /** - Close the write channel - - You only need to call this if writing is enabled - on the Console being managed. - */ - void closeOutput(); - - /** - The number of bytes available to read from the - Console being managed. - */ - int bytesAvailable() const; - - /** - The number of bytes remaining to be written - to the Console being managed - */ - int bytesToWrite() const; - -Q_SIGNALS: - /** - Emitted when there are bytes available to read from - the Console being managed - */ - void readyRead(); - - /** - Emitted when bytes are written to the Console - - \param bytes the number of bytes that were written - - \sa bytesAvailable() - */ - void bytesWritten(int bytes); - - /** - Emitted when the console input is closed - */ - void inputClosed(); - - /** - Emitted when the console output is closed - */ - void outputClosed(); - -private: - Q_DISABLE_COPY(ConsoleReference) - - friend class ConsoleReferencePrivate; - ConsoleReferencePrivate *d; - - friend class Console; -}; - -/** - \class ConsolePrompt qca_support.h QtCrypto - - Console prompt handler. - - This class provides a convenient way to get user input in a secure way, -as shown below: -\code -QCA::ConsolePrompt prompt; -prompt.getHidden("Passphrase"); -prompt.waitForFinished(); -QCA:SecureArray pass = prompt.result(); -\endcode - - \note It is not necessary to use waitForFinished(), because you can - just connect the finished() signal to a suitable method, however - command line (console) applications often require waitForFinished(). - - \ingroup UserAPI -*/ -class QCA_EXPORT ConsolePrompt : public QObject -{ - Q_OBJECT -public: - /** - Standard constructor - - \param parent the parent object for this object - */ - ConsolePrompt(QObject *parent = nullptr); - ~ConsolePrompt() override; - - /** - Allow the user to enter data without it being echo'd to - the terminal. This is particularly useful for entry - of passwords, passphrases and PINs. - - \param promptStr the prompt to display to the user - - \sa result() for how to get the input back. - */ - void getHidden(const QString &promptStr); - - /** - Obtain one character from the user - - \sa resultChar() for how to get the input back. - */ - void getChar(); - - /** - Block waiting for user input. - - You may wish to use the finished() signal to - avoid blocking. - */ - void waitForFinished(); - - /** - Obtain the result of the user input. - - This method is usually called to obtain data - from the user that was requested by the getHidden() - call. - */ - SecureArray result() const; - - /** - Obtain the result of the user input. - - This method is usually called to obtain data - from the user that was requested by the getChar() - call. - */ - QChar resultChar() const; - -Q_SIGNALS: - /** - Emitted when the user input activity has been - completed. - - This corresponds to the provision of a string - for getHidden() or a single character for getChar(). - - \sa waitForFinished - */ - void finished(); - -private: - Q_DISABLE_COPY(ConsolePrompt) - - class Private; - friend class Private; - Private *d; -}; class AbstractLogDevice; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7066839..85ae0d7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,7 @@ SET( SOURCES qca_securelayer.cpp qca_securemessage.cpp support/qpipe.cpp - support/console.cpp + # support/console.cpp support/synchronizer.cpp support/dirwatch.cpp support/syncthread.cpp @@ -52,8 +52,8 @@ SET( SOURCES IF (WIN32) SET( SOURCES ${SOURCES} qca_systemstore_win.cpp ) -elseif(APPLE) - set( SOURCES ${SOURCES} qca_systemstore_mac.cpp) + #elseif(APPLE) + # set( SOURCES ${SOURCES} qca_systemstore_mac.cpp) else() SET( SOURCES ${SOURCES} qca_systemstore_flatfile.cpp ) endif() @@ -130,24 +130,24 @@ if(WIN32) TARGET_LINK_LIBRARIES(${QCA_LIB_NAME} crypt32 ws2_32) endif() -if(APPLE) - set(COREFOUNDATION_LIBRARY "-framework CoreFoundation") - set(COREFOUNDATION_LIBRARY_SECURITY "-framework Security") - TARGET_LINK_LIBRARIES(${QCA_LIB_NAME} ${COREFOUNDATION_LIBRARY} ${COREFOUNDATION_LIBRARY_SECURITY}) - - if(NOT USE_RELATIVE_PATHS) - set_target_properties(${QCA_LIB_NAME} PROPERTIES - INSTALL_NAME_DIR "${QCA_LIBRARY_INSTALL_DIR}" - ) - endif() -endif() - -if(NOT ANDROID) - set_target_properties(${QCA_LIB_NAME} PROPERTIES - VERSION ${QCA_LIB_MAJOR_VERSION}.${QCA_LIB_MINOR_VERSION}.${QCA_LIB_PATCH_VERSION} - SOVERSION ${QCA_LIB_MAJOR_VERSION} - ) -endif() +#if(APPLE) +# set(COREFOUNDATION_LIBRARY "-framework CoreFoundation") +# set(COREFOUNDATION_LIBRARY_SECURITY "-framework Security") +# TARGET_LINK_LIBRARIES(${QCA_LIB_NAME} ${COREFOUNDATION_LIBRARY} ${COREFOUNDATION_LIBRARY_SECURITY}) +# +# if(NOT USE_RELATIVE_PATHS) +# set_target_properties(${QCA_LIB_NAME} PROPERTIES +# INSTALL_NAME_DIR "${QCA_LIBRARY_INSTALL_DIR}" +# ) +# endif() +#endif() + +#if(NOT ANDROID) +# set_target_properties(${QCA_LIB_NAME} PROPERTIES +# VERSION ${QCA_LIB_MAJOR_VERSION}.${QCA_LIB_MINOR_VERSION}.${QCA_LIB_PATCH_VERSION} +# SOVERSION ${QCA_LIB_MAJOR_VERSION} +# ) +#endif() set_target_properties(${QCA_LIB_NAME} PROPERTIES DEFINE_SYMBOL QCA_MAKEDLL -- 2.25.1