118QSslKey::QSslKey(
const QByteArray &encoded, QSsl::KeyAlgorithm algorithm,
119 QSsl::EncodingFormat encoding, QSsl::KeyType type,
const QByteArray &passPhrase)
120 : d(
new QSslKeyPrivate)
122 if (
auto *tlsKey = d->backend.get()) {
123 if (encoding == QSsl::Der)
124 tlsKey->decodeDer(type, algorithm, encoded, passPhrase,
true );
126 tlsKey->decodePem(type, algorithm, encoded, passPhrase,
true );
140QSslKey::QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat encoding,
141 QSsl::KeyType type,
const QByteArray &passPhrase)
142 : d(
new QSslKeyPrivate)
146 encoded = device->readAll();
148 if (
auto *tlsKey = d->backend.get()) {
149 if (encoding == QSsl::Der)
150 tlsKey->decodeDer(type, algorithm, encoded, passPhrase,
true );
152 tlsKey->decodePem(type, algorithm, encoded, passPhrase,
true );
283QByteArray QSslKey::toDer(
const QByteArray &passPhrase)
const
285 if (isNull() || algorithm() == QSsl::Opaque)
289 if (type() == QSsl::PrivateKey && !passPhrase.isEmpty())
292 QMap<QByteArray, QByteArray> headers;
293 if (
const auto *tlsKey = d->backend.get())
294 return tlsKey->derFromPem(toPem(passPhrase), &headers);
334bool QSslKey::operator==(
const QSslKey &other)
const
337 return other.isNull();
340 if (algorithm() != other.algorithm())
342 if (type() != other.type())
344 if (length() != other.length())
346 if (algorithm() == QSsl::Opaque)
347 return handle() == other.handle();
348 return toDer() == other.toDer();
358QDebug operator<<(QDebug debug,
const QSslKey &key)
360 QDebugStateSaver saver(debug);
361 debug.resetFormat().nospace();
363 << (key.type() == QSsl::PublicKey ?
"PublicKey" :
"PrivateKey")
364 <<
", " << (key.algorithm() == QSsl::Opaque ?
"OPAQUE" :
365 (key.algorithm() == QSsl::Rsa ?
"RSA" :
366 (key.algorithm() == QSsl::Dsa ?
"DSA" :
367 (key.algorithm() == QSsl::Dh ?
"DH" :
368 (key.algorithm() == QSsl::Ec ?
"EC" :
"ML-DSA")))))
369 <<
", " << key.length()