Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Add ByteArray based Input and Output classes

Useful for just encrypting / decrypting in memory
parent 4d91ca96
......@@ -179,6 +179,54 @@ private:
};
#endif // QT_NO_CLIPBOARD
class ByteArrayInput: public Input
{
public:
explicit ByteArrayInput(QByteArray *data):
m_buffer(std::shared_ptr<QBuffer>(new QBuffer(data)))
{
if (!m_buffer->open(QIODevice::ReadOnly))
throw Exception(gpg_error(GPG_ERR_EIO),
QStringLiteral("Could not open bytearray for reading?!"));
}
void setLabel(const QString &label) override
{
m_label = label;
}
QString label() const override
{
return m_label;
}
std::shared_ptr<QIODevice> ioDevice() const override
{
return m_buffer;
}
unsigned long long size() const override
{
return m_buffer ? m_buffer->buffer().size() : 0;
}
QString errorString() const override
{
return QString();
}
unsigned int classification() const override
{
return 0;
}
private:
std::shared_ptr<QBuffer> m_buffer;
QString m_label;
};
}
std::shared_ptr<Input> Input::createFromByteArray(QByteArray *data, const QString &label)
{
std::shared_ptr<ByteArrayInput> po(new ByteArrayInput(data));
po->setLabel(label);
return po;
}
std::shared_ptr<Input> Input::createFromPipeDevice(assuan_fd_t fd, const QString &label)
......
......@@ -76,6 +76,7 @@ public:
#ifndef QT_NO_CLIPBOARD
static std::shared_ptr<Input> createFromClipboard();
#endif
static std::shared_ptr<Input> createFromByteArray(QByteArray *data, const QString &label);
};
}
......
......@@ -444,6 +444,52 @@ private:
};
#endif // QT_NO_CLIPBOARD
class ByteArrayOutput: public OutputImplBase
{
public:
explicit ByteArrayOutput(QByteArray *data):
m_buffer(std::shared_ptr<QBuffer>(new QBuffer(data)))
{
if (!m_buffer->open(QIODevice::WriteOnly))
throw Exception(gpg_error(GPG_ERR_EIO),
QStringLiteral("Could not open bytearray for writing?!"));
}
QString label() const override
{
return m_label;
}
void setLabel(const QString &label) override
{
m_label = label;
}
std::shared_ptr<QIODevice> ioDevice() const override
{
return m_buffer;
}
void doFinalize() override
{
m_buffer->close();
}
void doCancel() override
{
m_buffer->close();
}
private:
QString doErrorString() const override
{
return QString();
}
private:
QString m_label;
std::shared_ptr<QBuffer> m_buffer;
};
}
std::shared_ptr<Output> Output::createFromPipeDevice(assuan_fd_t fd, const QString &label)
......@@ -699,3 +745,10 @@ std::shared_ptr<Input> Input::createFromOutput(const std::shared_ptr<Output> &ou
return {};
}
}
std::shared_ptr<Output> Output::createFromByteArray(QByteArray *data, const QString &label)
{
auto ret = std::shared_ptr<ByteArrayOutput>(new ByteArrayOutput(data));
ret->setLabel(label);
return ret;
}
......@@ -94,6 +94,7 @@ public:
#ifndef QT_NO_CLIPBOARD
static std::shared_ptr<Output> createFromClipboard();
#endif
static std::shared_ptr<Output> createFromByteArray(QByteArray *data, const QString &label);
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment