/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt for Python.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

// default includes
#include <shiboken.h>
#ifndef QT_NO_VERSION_TAGGING
#  define QT_NO_VERSION_TAGGING
#endif
#include <QDebug>
#include <pysidesignal.h>
#include <pysideproperty.h>
#include <pyside.h>
#include <pysideqenum.h>
#include <feature_select.h>
QT_WARNING_DISABLE_DEPRECATED

#include <typeinfo>
#include <iterator>

// module include
#include "pyside6_qtnetwork_python.h"

// main header
#include "qpassworddigestor_wrapper.h"

// inner classes

// Extra includes
#include <qbytearray.h>
#include <qpassworddigestor.h>


#include <cctype>
#include <cstring>



template <class T>
static const char *typeNameOf(const T &t)
{
    const char *typeName =  typeid(t).name();
    auto size = std::strlen(typeName);
#if defined(Q_CC_MSVC) // MSVC: "class QPaintDevice * __ptr64"
    if (auto lastStar = strchr(typeName, '*')) {
        // MSVC: "class QPaintDevice * __ptr64"
        while (*--lastStar == ' ') {
        }
        size = lastStar - typeName + 1;
    }
#else // g++, Clang: "QPaintDevice *" -> "P12QPaintDevice"
    if (size > 2 && typeName[0] == 'P' && std::isdigit(typeName[1])) {
        ++typeName;
        --size;
    }
#endif
    char *result = new char[size + 1];
    result[size] = '\0';
    memcpy(result, typeName, size);
    return result;
}


// Target ---------------------------------------------------------

extern "C" {
static PyObject *Sbk_QPasswordDigestorFunc_deriveKeyPbkdf1(PyObject *self, PyObject *args)
{
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtNetwork.QPasswordDigestor.deriveKeyPbkdf1";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp[5];
    SBK_UNUSED(pythonToCpp)
    const Py_ssize_t numArgs = PyTuple_GET_SIZE(args);
    SBK_UNUSED(numArgs)
    PyObject *pyArgs[] = {0, 0, 0, 0, 0};

    // invalid argument lengths


    if (!PyArg_UnpackTuple(args, "deriveKeyPbkdf1", 5, 5, &(pyArgs[0]), &(pyArgs[1]), &(pyArgs[2]), &(pyArgs[3]), &(pyArgs[4])))
        return {};


    // Overloaded function decisor
    // 0: static QPasswordDigestor::deriveKeyPbkdf1(QCryptographicHash::Algorithm,QByteArray,QByteArray,int,quint64)->QByteArray
    if (numArgs == 5
        && (pythonToCpp[0] = Shiboken::Conversions::pythonToCppConversion(PepType_SETP(reinterpret_cast<SbkEnumType *>(SbkPySide6_QtCoreTypes[SBK_QCRYPTOGRAPHICHASH_ALGORITHM_IDX]))->converter, (pyArgs[0])))
        && (pythonToCpp[1] = Shiboken::Conversions::pythonToCppReferenceConversion(SbkPySide6_QtCoreTypes[SBK_QBYTEARRAY_IDX], (pyArgs[1])))
        && (pythonToCpp[2] = Shiboken::Conversions::pythonToCppReferenceConversion(SbkPySide6_QtCoreTypes[SBK_QBYTEARRAY_IDX], (pyArgs[2])))
        && (pythonToCpp[3] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArgs[3])))
        && (pythonToCpp[4] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<quint64>(), (pyArgs[4])))) {
        overloadId = 0; // deriveKeyPbkdf1(QCryptographicHash::Algorithm,QByteArray,QByteArray,int,quint64)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QPasswordDigestorFunc_deriveKeyPbkdf1_TypeError;

    // Call function/method
    {
        ::QCryptographicHash::Algorithm cppArg0{QCryptographicHash::Md4};
        pythonToCpp[0](pyArgs[0], &cppArg0);
        if (!Shiboken::Object::isValid(pyArgs[1]))
            return {};
        ::QByteArray cppArg1_local;
        ::QByteArray *cppArg1 = &cppArg1_local;
        if (pythonToCpp[1].isValue())
            pythonToCpp[1](pyArgs[1], &cppArg1_local);
        else
            pythonToCpp[1](pyArgs[1], &cppArg1);

        if (!Shiboken::Object::isValid(pyArgs[2]))
            return {};
        ::QByteArray cppArg2_local;
        ::QByteArray *cppArg2 = &cppArg2_local;
        if (pythonToCpp[2].isValue())
            pythonToCpp[2](pyArgs[2], &cppArg2_local);
        else
            pythonToCpp[2](pyArgs[2], &cppArg2);

        int cppArg3;
        pythonToCpp[3](pyArgs[3], &cppArg3);
        quint64 cppArg4;
        pythonToCpp[4](pyArgs[4], &cppArg4);

        if (!PyErr_Occurred()) {
            // deriveKeyPbkdf1(QCryptographicHash::Algorithm,QByteArray,QByteArray,int,quint64)
            QByteArray cppResult = ::QPasswordDigestor::deriveKeyPbkdf1(cppArg0, *cppArg1, *cppArg2, cppArg3, cppArg4);
            pyResult = Shiboken::Conversions::copyToPython(SbkPySide6_QtCoreTypes[SBK_QBYTEARRAY_IDX], &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;

    Sbk_QPasswordDigestorFunc_deriveKeyPbkdf1_TypeError:
        Shiboken::setErrorAboutWrongArguments(args, fullName, errInfo);
        return {};
}

static PyObject *Sbk_QPasswordDigestorFunc_deriveKeyPbkdf2(PyObject *self, PyObject *args)
{
    PyObject *pyResult{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtNetwork.QPasswordDigestor.deriveKeyPbkdf2";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp[5];
    SBK_UNUSED(pythonToCpp)
    const Py_ssize_t numArgs = PyTuple_GET_SIZE(args);
    SBK_UNUSED(numArgs)
    PyObject *pyArgs[] = {0, 0, 0, 0, 0};

    // invalid argument lengths


    if (!PyArg_UnpackTuple(args, "deriveKeyPbkdf2", 5, 5, &(pyArgs[0]), &(pyArgs[1]), &(pyArgs[2]), &(pyArgs[3]), &(pyArgs[4])))
        return {};


    // Overloaded function decisor
    // 0: static QPasswordDigestor::deriveKeyPbkdf2(QCryptographicHash::Algorithm,QByteArray,QByteArray,int,quint64)->QByteArray
    if (numArgs == 5
        && (pythonToCpp[0] = Shiboken::Conversions::pythonToCppConversion(PepType_SETP(reinterpret_cast<SbkEnumType *>(SbkPySide6_QtCoreTypes[SBK_QCRYPTOGRAPHICHASH_ALGORITHM_IDX]))->converter, (pyArgs[0])))
        && (pythonToCpp[1] = Shiboken::Conversions::pythonToCppReferenceConversion(SbkPySide6_QtCoreTypes[SBK_QBYTEARRAY_IDX], (pyArgs[1])))
        && (pythonToCpp[2] = Shiboken::Conversions::pythonToCppReferenceConversion(SbkPySide6_QtCoreTypes[SBK_QBYTEARRAY_IDX], (pyArgs[2])))
        && (pythonToCpp[3] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<int>(), (pyArgs[3])))
        && (pythonToCpp[4] = Shiboken::Conversions::pythonToCppConversion(Shiboken::Conversions::PrimitiveTypeConverter<quint64>(), (pyArgs[4])))) {
        overloadId = 0; // deriveKeyPbkdf2(QCryptographicHash::Algorithm,QByteArray,QByteArray,int,quint64)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QPasswordDigestorFunc_deriveKeyPbkdf2_TypeError;

    // Call function/method
    {
        ::QCryptographicHash::Algorithm cppArg0{QCryptographicHash::Md4};
        pythonToCpp[0](pyArgs[0], &cppArg0);
        if (!Shiboken::Object::isValid(pyArgs[1]))
            return {};
        ::QByteArray cppArg1_local;
        ::QByteArray *cppArg1 = &cppArg1_local;
        if (pythonToCpp[1].isValue())
            pythonToCpp[1](pyArgs[1], &cppArg1_local);
        else
            pythonToCpp[1](pyArgs[1], &cppArg1);

        if (!Shiboken::Object::isValid(pyArgs[2]))
            return {};
        ::QByteArray cppArg2_local;
        ::QByteArray *cppArg2 = &cppArg2_local;
        if (pythonToCpp[2].isValue())
            pythonToCpp[2](pyArgs[2], &cppArg2_local);
        else
            pythonToCpp[2](pyArgs[2], &cppArg2);

        int cppArg3;
        pythonToCpp[3](pyArgs[3], &cppArg3);
        quint64 cppArg4;
        pythonToCpp[4](pyArgs[4], &cppArg4);

        if (!PyErr_Occurred()) {
            // deriveKeyPbkdf2(QCryptographicHash::Algorithm,QByteArray,QByteArray,int,quint64)
            QByteArray cppResult = ::QPasswordDigestor::deriveKeyPbkdf2(cppArg0, *cppArg1, *cppArg2, cppArg3, cppArg4);
            pyResult = Shiboken::Conversions::copyToPython(SbkPySide6_QtCoreTypes[SBK_QBYTEARRAY_IDX], &cppResult);
        }
    }

    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;

    Sbk_QPasswordDigestorFunc_deriveKeyPbkdf2_TypeError:
        Shiboken::setErrorAboutWrongArguments(args, fullName, errInfo);
        return {};
}


static const char *Sbk_QPasswordDigestor_PropertyStrings[] = {
    nullptr // Sentinel
};

static PyMethodDef Sbk_QPasswordDigestor_methods[] = {
    {"deriveKeyPbkdf1", reinterpret_cast<PyCFunction>(Sbk_QPasswordDigestorFunc_deriveKeyPbkdf1), METH_VARARGS|METH_STATIC},
    {"deriveKeyPbkdf2", reinterpret_cast<PyCFunction>(Sbk_QPasswordDigestorFunc_deriveKeyPbkdf2), METH_VARARGS|METH_STATIC},

    {nullptr, nullptr} // Sentinel
};

} // extern "C"

static int Sbk_QPasswordDigestor_traverse(PyObject *self, visitproc visit, void *arg)
{
    return SbkObject_TypeF()->tp_traverse(self, visit, arg);
}
static int Sbk_QPasswordDigestor_clear(PyObject *self)
{
    return reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())->tp_clear(self);
}
// Class Definition -----------------------------------------------
extern "C" {
static PyTypeObject *_Sbk_QPasswordDigestor_Type = nullptr;
static PyTypeObject *Sbk_QPasswordDigestor_TypeF(void)
{
    return _Sbk_QPasswordDigestor_Type;
}

static PyType_Slot Sbk_QPasswordDigestor_slots[] = {
    {Py_tp_base,        nullptr}, // inserted by introduceWrapperType
    {Py_tp_dealloc,     reinterpret_cast<void *>(Sbk_object_dealloc /* PYSIDE-832: Prevent replacement of "0" with subtype_dealloc. */)},
    {Py_tp_repr,        nullptr},
    {Py_tp_hash,        nullptr},
    {Py_tp_call,        nullptr},
    {Py_tp_str,         nullptr},
    {Py_tp_getattro,    nullptr},
    {Py_tp_setattro,    nullptr},
    {Py_tp_traverse,    reinterpret_cast<void *>(Sbk_QPasswordDigestor_traverse)},
    {Py_tp_clear,       reinterpret_cast<void *>(Sbk_QPasswordDigestor_clear)},
    {Py_tp_richcompare, nullptr},
    {Py_tp_iter,        nullptr},
    {Py_tp_iternext,    nullptr},
    {Py_tp_methods,     reinterpret_cast<void *>(Sbk_QPasswordDigestor_methods)},
    {Py_tp_getset,      nullptr},
    {Py_tp_init,        nullptr},
    {Py_tp_new,         reinterpret_cast<void *>(SbkObjectTpNew)},
    {0, nullptr}
};
static PyType_Spec Sbk_QPasswordDigestor_spec = {
    "2:PySide6.QtNetwork.QPasswordDigestor",
    sizeof(SbkObject),
    0,
    Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
    Sbk_QPasswordDigestor_slots
};

} //extern "C"


// Type conversion functions.

// The signatures string for the functions.
// Multiple signatures have their index "n:" in front.
static const char *QtNetworkQPasswordDigestor_SignatureStrings[] = {
    "PySide6.QtNetwork.QPasswordDigestor.deriveKeyPbkdf1(algorithm:PySide6.QtCore.QCryptographicHash.Algorithm,password:typing.Union[PySide6.QtCore.QByteArray, char*],salt:typing.Union[PySide6.QtCore.QByteArray, char*],iterations:int,dkLen:quint64)->PySide6.QtCore.QByteArray",
    "PySide6.QtNetwork.QPasswordDigestor.deriveKeyPbkdf2(algorithm:PySide6.QtCore.QCryptographicHash.Algorithm,password:typing.Union[PySide6.QtCore.QByteArray, char*],salt:typing.Union[PySide6.QtCore.QByteArray, char*],iterations:int,dkLen:quint64)->PySide6.QtCore.QByteArray",
    nullptr}; // Sentinel

void init_QtNetworkQPasswordDigestor(PyObject *module)
{
    _Sbk_QPasswordDigestor_Type = Shiboken::ObjectType::introduceWrapperType(
        module,
        "QPasswordDigestor",
        "QPasswordDigestor",
        &Sbk_QPasswordDigestor_spec,
        nullptr,
        0,
        0,
        0);
    auto *pyType = Sbk_QPasswordDigestor_TypeF(); // references _Sbk_QPasswordDigestor_Type
    InitSignatureStrings(pyType, QtNetworkQPasswordDigestor_SignatureStrings);
    SbkObjectType_SetPropertyStrings(reinterpret_cast<PyTypeObject *>(_Sbk_QPasswordDigestor_Type), Sbk_QPasswordDigestor_PropertyStrings);
    SbkPySide6_QtNetworkTypes[SBK_QtNetworkQPASSWORDDIGESTOR_IDX]
        = Sbk_QPasswordDigestor_TypeF();


}
