Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtlskey_st.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// Copyright (C) 2014 Jeremy Lainé <jeremy.laine@m4x.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "qtlskey_st_p.h"
6
7#include <QtNetwork/private/qsslkey_p.h>
8
9#include <QtCore/qbytearray.h>
10
11#include <CommonCrypto/CommonCrypto.h>
12
13#include <cstddef>
14
16
17namespace QTlsPrivate {
18namespace {
19
20// Before this code was located in qsslkey_mac.cpp.
21QByteArray wrapCCCrypt(CCOperation ccOp, QSslKeyPrivate::Cipher cipher,
22 const QByteArray &data, const QByteArray &key,
23 const QByteArray &iv)
24{
25 int blockSize = {};
26 CCAlgorithm ccAlgorithm = {};
27 switch (cipher) {
28 case Cipher::DesCbc:
29 blockSize = kCCBlockSizeDES;
30 ccAlgorithm = kCCAlgorithmDES;
31 break;
33 blockSize = kCCBlockSize3DES;
34 ccAlgorithm = kCCAlgorithm3DES;
35 break;
36 case Cipher::Rc2Cbc:
37 blockSize = kCCBlockSizeRC2;
38 ccAlgorithm = kCCAlgorithmRC2;
39 break;
43 blockSize = kCCBlockSizeAES128;
44 ccAlgorithm = kCCAlgorithmAES;
45 break;
46 }
47 std::size_t plainLength = 0;
48 QByteArray plain(data.size() + blockSize, 0);
49 CCCryptorStatus status = CCCrypt(ccOp, ccAlgorithm, kCCOptionPKCS7Padding,
50 key.constData(), std::size_t(key.size()),
51 iv.constData(), data.constData(), std::size_t(data.size()),
52 plain.data(), std::size_t(plain.size()), &plainLength);
53 if (status == kCCSuccess)
54 return plain.left(int(plainLength));
55
56 return {};
57}
58
59} // Unnamed namespace.
60
62 const QByteArray &key, const QByteArray &iv) const
63{
64 return wrapCCCrypt(kCCDecrypt, cipher, data, key, iv);
65}
66
68 const QByteArray &key, const QByteArray &iv) const
69{
70 return wrapCCCrypt(kCCEncrypt, cipher, data, key, iv);
71}
72
73} // namespace QTlsPrivate
74
\inmodule QtCore
Definition qbytearray.h:57
QByteArray decrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
QByteArray encrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
Combined button and popup list for selecting options.
Namespace containing onternal types that TLS backends implement.
const int blockSize
GLuint64 key
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data