xca/lib/BioByteArray.h
Christian Hohnstaedt ea453d4336 Encapsulate all BIOs in the BioByteArray class
If we have a QByteArray (ba) and must provide it to
a BIO* expecting OpenSSL function, the following
construct provides it: BioByteArray(ba).ro()
directly providing the QByteArray buffer as BIO

It also supports mixed writes:
  BIO_write(bba, buf, size)
  bba += QByteArray
2020-04-06 22:07:57 +02:00

45 lines
1.0 KiB
C++

/* vi: set sw=4 ts=4:
*
* Copyright (C) 2020 Christian Hohnstaedt.
*
* All rights reserved.
*/
#ifndef __BIOBYTEARRAY_H
#define __BIOBYTEARRAY_H
#include <QByteArray>
#include <openssl/bio.h>
class BioByteArray
{
protected:
BIO *read_write;
BIO *read_only;
QByteArray store;
void set(const QByteArray &qba);
void add(const QByteArray &qba);
void biowrite(const QByteArray &qba);
void cleanse_and_free(BIO *bio);
public:
BioByteArray(const QByteArray &qba) :
read_write(NULL), read_only(NULL), store(qba) { }
BioByteArray(const BioByteArray &bba) :
read_write(NULL), read_only(NULL), store(bba.byteArray()) { }
BioByteArray() :
read_write(NULL), read_only(NULL), store() { }
~BioByteArray();
BIO *bio();
BIO *ro();
QByteArray byteArray() const;
operator BIO*();
operator QByteArray();
BioByteArray &operator = (const BioByteArray &other);
BioByteArray &operator = (const QByteArray &qba);
BioByteArray &operator += (const BioByteArray &other);
BioByteArray &operator += (const QByteArray &qba);
};
#endif