⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsslsocket.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*!    Returns the socket's SSL protocol. By default, \l QSsl::SslV3 is used.    \value setProtocol()*/QSsl::SslProtocol QSslSocket::protocol() const{    Q_D(const QSslSocket);    return d->protocol;}/*!    Sets the socket's SSL protocol to \a protocol. This will affect the next    initiated handshake; calling this function on an already-encrypted socket    will not affect the socket's protocol.*/void QSslSocket::setProtocol(QSsl::SslProtocol protocol){    Q_D(QSslSocket);    d->protocol = protocol;}/*!    \reimp    Returns the number of decrypted bytes that are immediately available for    reading.*/qint64 QSslSocket::bytesAvailable() const{    Q_D(const QSslSocket);    if (d->mode == UnencryptedMode)        return QIODevice::bytesAvailable() + (d->plainSocket ? d->plainSocket->bytesAvailable() : 0);    return QIODevice::bytesAvailable() + d->readBuffer.size();}/*!    \reimp    Returns the number of uneccrypted bytes that are waiting to be encrypted    and written to the network.*/qint64 QSslSocket::bytesToWrite() const{    Q_D(const QSslSocket);    if (d->mode == UnencryptedMode)        return d->plainSocket ? d->plainSocket->bytesToWrite() : 0;    return d->writeBuffer.size();}/*!    \reimp    Returns true if you can read one while line (terminated by a single ASCII    '\n' character) of decrypted characters; otherwise, false is returned.*/bool QSslSocket::canReadLine() const{    Q_D(const QSslSocket);    if (d->mode == UnencryptedMode)        return QIODevice::canReadLine() || (d->plainSocket && d->plainSocket->canReadLine());    return QIODevice::canReadLine() || (!d->readBuffer.isEmpty() && d->readBuffer.canReadLine());}/*!    \reimp*/void QSslSocket::close(){#ifdef QSSLSOCKET_DEBUG    qDebug() << "QSslSocket::close()";#endif    QTcpSocket::close();}/*!    \reimp*/bool QSslSocket::atEnd() const{    Q_D(const QSslSocket);    if (d->mode == UnencryptedMode)        return QIODevice::atEnd() && (!d->plainSocket || d->plainSocket->atEnd());    return QIODevice::atEnd() && d->readBuffer.isEmpty();}/*!    This function writes as much as possible from the internal write buffer to    the underlying network socket, without blocking. If any data was written,    this function returns true; otherwise false is returned.    Call this function if you need QSslSocket to start sending buffered data    immediately. The number of bytes successfully written depends on the    operating system. In most cases, you do not need to call this function,    because QAbstractSocket will start sending data automatically once control    goes back to the event loop. In the absence of an event loop, call    waitForBytesWritten() instead.    \sa write(), waitForBytesWritten()*/// Note! docs copied from QAbstractSocket::flush()bool QSslSocket::flush(){    Q_D(QSslSocket);#ifdef QSSLSOCKET_DEBUG    qDebug() << "QSslSocket::flush()";#endif    return d->plainSocket ? d->plainSocket->flush() : false;}/*!    Aborts the current connection and resets the socket. Unlike    disconnectFromHost(), this function immediately closes the socket,    clearing any pending data in the write buffer.    \sa disconnectFromHost(), close()*/void QSslSocket::abort(){    Q_D(QSslSocket);#ifdef QSSLSOCKET_DEBUG    qDebug() << "QSslSocket::abort()";#endif    if (d->plainSocket)        d->plainSocket->abort();}/*!    Sets the socket's local certificate to \a certificate. The local    certificate is necessary if you need to confirm your identity to the    peer. It is used together with the private key; if you set the local    certificate, you must also set the private key.    The local certificate and private key are always necessary for server    sockets, but are also rarely used by client sockets if the server requires    the client to authenticate.    \sa localCertificate(), setPrivateKey()*/void QSslSocket::setLocalCertificate(const QSslCertificate &certificate){    Q_D(QSslSocket);    d->localCertificate = certificate;}/*!    \overload    Sets the socket's local \l {QSslCertificate} {certificate} to the    first one found in file \a path, which is parsed according to the     specified \a format.*/void QSslSocket::setLocalCertificate(const QString &path,                                     QSsl::EncodingFormat format){    Q_D(QSslSocket);    QFile file(path);    if (file.open(QIODevice::ReadOnly | QIODevice::Text))        d->localCertificate = QSslCertificate(file.readAll(), format);}/*!    Returns the socket's local \l {QSslCertificate} {certificate}, or    an empty certificate if no local certificate has been assigned.    \sa setLocalCertificate(), privateKey()*/QSslCertificate QSslSocket::localCertificate() const{    Q_D(const QSslSocket);    return d->localCertificate;}/*!    Returns the peer's digital certificate (i.e., the immediate    certificate of the host you are connected to), or a null    certificate, if the peer has not assigned a certificate.        The peer certificate is checked automatically during the    handshake phase, so this function is normally used to fetch    the certificate for display or for connection diagnostic    purposes. It contains information about the peer, including    its host name, the certificate issuer, and the peer's public    key.    Because the peer certificate is set during the handshake phase, it    is safe to access the peer certificate from a slot connected to    the sslErrors() signal or the encrypted() signal.    If a null certificate is returned, it can mean the SSL handshake    failed, or it can mean the host you are connected to doesn't have    a certificate, or it can mean there is no connection.    If you want to check the peer's complete chain of certificates,    use peerCertificateChain() to get them all at once.    \sa peerCertificateChain()*/QSslCertificate QSslSocket::peerCertificate() const{    Q_D(const QSslSocket);    return d->peerCertificate;}/*!    Returns the peer's chain of digital certificates, or an empty list    of certificates.    Peer certificates are checked automatically during the handshake    phase. This function is normally used to fetch certificates for    display, or for performing connection diagnostics. Certificates    contain information about the peer and the certificate issuers,    including host name, issuer names, and issuer public keys.    The peer certificates are set in QSslSocket during the handshake    phase, so it is safe to call this function from a slot connected    to the sslErrors() signal or the encrypted() signal.    If an empty list is returned, it can mean the SSL handshake    failed, or it can mean the host you are connected to doesn't have    a certificate, or it can mean there is no connection.    If you want to get only the peer's immediate certificate, use    peerCertificate().    \sa peerCertificate()*/QList<QSslCertificate> QSslSocket::peerCertificateChain() const{    Q_D(const QSslSocket);    return d->peerCertificateChain;}/*!    Returns the socket's cryptographic \l {QSslCipher} {cipher}, or a    null cipher if the connection isn't encrypted. The socket's cipher    for the session is set during the handshake phase. The cipher is    used to encrypt and decrypt data transmitted through the socket.    QSslSocket also provides functions for setting the ordered list of    ciphers from which the handshake phase will eventually select the    session cipher. This ordered list must be in place before the    handshake phase begins.    \sa ciphers(), setCiphers(), setDefaultCiphers(), defaultCiphers(),    supportedCiphers()*/QSslCipher QSslSocket::sessionCipher() const{    Q_D(const QSslSocket);    return d->sessionCipher();}/*!    Sets the socket's private \l {QSslKey} {key} to \a key. The    private key and the local \l {QSslCertificate} {certificate} are    used by clients and servers that must prove their identity to    SSL peers.    Both the key and the local certificate are required if you are    creating an SSL server socket. If you are creating an SSL client    socket, the key and local certificate are required if your client    must identify itself to an SSL server.    \sa privateKey(), setLocalCertificate()*/void QSslSocket::setPrivateKey(const QSslKey &key){    Q_D(QSslSocket);    d->privateKey = key;}/*!    \overload    Reads the string in file \a fileName and decodes it using    a specified \a algorithm and encoding \a format to construct    an \l {QSslKey} {SSL key}. If the encoded key is encrypted,    \a passPhrase is used to decrypt it.    The socket's private key is set to the constructed key. The    private key and the local \l {QSslCertificate} {certificate} are    used by clients and servers that must prove their identity to SSL    peers.    Both the key and the local certificate are required if you are    creating an SSL server socket. If you are creating an SSL client    socket, the key and local certificate are required if your client    must identify itself to an SSL server.        \sa privateKey(), setLocalCertificate()*/void QSslSocket::setPrivateKey(const QString &fileName, QSsl::KeyAlgorithm algorithm,                               QSsl::EncodingFormat format, const QByteArray &passPhrase){    Q_D(QSslSocket);    QFile file(fileName);    if (file.open(QIODevice::ReadOnly)) {        d->privateKey = QSslKey(file.readAll(), algorithm,				format, QSsl::PrivateKey, passPhrase);    }}/*!    Returns this socket's private key.    \sa setPrivateKey(), localCertificate()*/QSslKey QSslSocket::privateKey() const{    Q_D(const QSslSocket);    return d->privateKey;}/*!    Returns this socket's current cryptographic cipher suite. This    list is used during the socket's handshake phase for choosing a    session cipher. The returned list of ciphers is ordered by    descending preference. (i.e., the first cipher in the list is the    most preferred cipher). The session cipher will be the first one    in the list that is also supported by the peer.    By default, the handshake phase can choose any of the ciphers    supported by this system's SSL libraries, which may vary from    system to system. The list of ciphers supported by this system's    SSL libraries is returned by supportedCiphers(). You can restrict    the list of ciphers used for choosing the session cipher for this    socket by calling setCiphers() with a subset of the supported    ciphers. You can revert to using the entire set by calling    setCiphers() with the list returned by supportedCiphers().    You can restrict the list of ciphers used for choosing the session    cipher for \e all sockets by calling setDefaultCiphers() with a    subset of the supported ciphers. You can revert to using the    entire set by calling setCiphers() with the list returned by    supportedCiphers().    \sa setCiphers(), defaultCiphers(), setDefaultCiphers(), supportedCiphers()*/QList<QSslCipher> QSslSocket::ciphers() const{    Q_D(const QSslSocket);    return d->ciphers;}/*!    Sets the cryptographic cipher suite for this socket to \a ciphers,    which must contain a subset of the ciphers in the list returned by    supportedCiphers().    Restricting the cipher suite must be done before the handshake    phase, where the session cipher is chosen.    \sa ciphers(), setDefaultCiphers(), supportedCiphers()*/void QSslSocket::setCiphers(const QList<QSslCipher> &ciphers){    Q_D(QSslSocket);    d->ciphers = ciphers;}/*!    Sets the cryptographic cipher suite for this socket to \a ciphers, which    is a colon-separated list of cipher suite names. The ciphers are listed in    order of preference, starting with the most preferred cipher. For example:    \code        QSslSocket socket;        socket.setCiphers("DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA");    \endcode    Each cipher name in \a ciphers must be the name of a cipher in the    list returned by supportedCiphers().  Restricting the cipher suite    must be done before the handshake phase, where the session cipher    is chosen.    \sa ciphers(), setDefaultCiphers(), supportedCiphers()*/void QSslSocket::setCiphers(const QString &ciphers){    Q_D(QSslSocket);    d->ciphers.clear();    foreach (QString cipherName, ciphers.split(QLatin1String(":"),QString::SkipEmptyParts)) {        for (int i = 0; i < 3; ++i) {            // ### Crude            QSslCipher cipher(cipherName, QSsl::SslProtocol(i));            if (!cipher.isNull())                d->ciphers << cipher;        }    }}/*!    Sets the default cryptographic cipher suite for all sockets in    this application to \a ciphers, which must contain a subset of the    ciphers in the list returned by supportedCiphers().    Restricting the default cipher suite only affects SSL sockets    that perform their handshake phase after the default cipher    suite has been changed.    \sa setCiphers(), defaultCiphers(), supportedCiphers()*/void QSslSocket::setDefaultCiphers(const QList<QSslCipher> &ciphers){    QSslSocketPrivate::setDefaultCiphers(ciphers);}/*!    Returns the default cryptographic cipher suite for all sockets in    this application. This list is used during the socket's handshake    phase when negotiating with the peer to choose a session cipher.    The list is ordered by preference (i.e., the first cipher in the    list is the most preferred cipher).    By default, the handshake phase can choose any of the ciphers    supported by this system's SSL libraries, which may vary from    system to system. The list of ciphers supported by this system's    SSL libraries is returned by supportedCiphers().    \sa supportedCiphers()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -