[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [KSecretService] 0477014: SecureBufferPrivate can do without signal
From: Michael Leupold <lemma () confuego ! org>
Date: 2010-11-09 19:14:25
Message-ID: 20101109191425.18837A60D5 () git ! kde ! org
[Download RAW message or body]
commit 04770145ea5d89b52c6d5c0a0675712af802e9f5
branch master
Author: Michael Leupold <lemma@confuego.org>
Date: Thu May 13 06:57:38 2010 +0000
SecureBufferPrivate can do without signal reemissions.
Implement data() and setData() calls and adapt the test.
svn path=/trunk/playground/base/ksecretservice/; revision=1126172
diff --git a/backend/securebuffer.cpp b/backend/securebuffer.cpp
index d30f909..5d419ea 100644
--- a/backend/securebuffer.cpp
+++ b/backend/securebuffer.cpp
@@ -30,16 +30,12 @@ SecureBuffer::SecureBuffer(QObject *parent)
: QIODevice(parent), d(new SecureBufferPrivate(this))
{
d->buf = &d->defaultBuf;
- connect(d, SIGNAL(bytesWritten(qint64)), SIGNAL(bytesWritten(qint64)));
- connect(d, SIGNAL(readyRead()), SIGNAL(readyRead()));
}
SecureBuffer::SecureBuffer(QCA::SecureArray *buf, QObject *parent)
: QIODevice(parent), d(new SecureBufferPrivate(this))
{
d->buf = buf ? buf : &d->defaultBuf;
- connect(d, SIGNAL(bytesWritten(qint64)), SIGNAL(bytesWritten(qint64)));
- connect(d, SIGNAL(readyRead()), SIGNAL(readyRead()));
}
SecureBuffer::~SecureBuffer()
@@ -51,11 +47,6 @@ QCA::SecureArray &SecureBuffer::buffer()
return *d->buf;
}
-const QCA::SecureArray &SecureBuffer::buffer() const
-{
- return *d->buf;
-}
-
void SecureBuffer::setBuffer(QCA::SecureArray *secureArray) const
{
if (isOpen()) {
@@ -71,6 +62,36 @@ void SecureBuffer::setBuffer(QCA::SecureArray *secureArray) const
d->ioIndex = 0;
}
+const QCA::SecureArray &SecureBuffer::data() const
+{
+ return *d->buf;
+}
+
+void SecureBuffer::setData(const QCA::SecureArray &data)
+{
+ if (isOpen()) {
+ qWarning("SecureBuffer::setData: Buffer is open");
+ return;
+ }
+ *d->buf = data;
+ d->ioIndex = 0;
+}
+
+void SecureBuffer::setData(const QByteArray &data)
+{
+ if (isOpen()) {
+ qWarning("SecureBuffer::setData: Buffer is open");
+ return;
+ }
+ *d->buf = data;
+ d->ioIndex = 0;
+}
+
+void SecureBuffer::setData(const char *data, int size)
+{
+ setData(QByteArray(data, size));
+}
+
bool SecureBuffer::open(QIODevice::OpenMode mode)
{
// always operate in Unbuffered mode for security reasons.
diff --git a/backend/securebuffer.h b/backend/securebuffer.h
index 417d1f4..a1acd6a 100644
--- a/backend/securebuffer.h
+++ b/backend/securebuffer.h
@@ -71,15 +71,6 @@ public:
QCA::SecureArray &buffer();
/**
- Returns a constant reference to the SecureBuffer's internal
- buffer.
-
- \return a constant reference to the internal buffer
- \sa setBuffer(), data()
- */
- const QCA::SecureArray &buffer() const;
-
- /**
Make the SecureBuffer use the SecureArray pointed to by \a
secureArray as its internal storage. The SecureBuffer does
not take ownership of the SecureArray. The caller is responsible
@@ -97,6 +88,40 @@ public:
void setBuffer(QCA::SecureArray *secureArray) const;
/**
+ Returns the data contained in the buffer.
+
+ \return the data contained the buffer
+ \sa buffer(), setBuffer(), setData()
+ */
+ const QCA::SecureArray &data() const;
+
+ /**
+ Copy the contents of \a data to the internal buffer replacing all
+ previous contents. This does nothing if isOpen() is true.
+
+ \param data data to copy to the internal buffer
+ */
+ void setData(const QCA::SecureArray &data);
+
+ /**
+ Copy the contents of \a data to the internal buffer replacing all
+ previous contents. This does nothing if isOpen() is true.
+
+ \param data data to copy to the internal buffer
+ */
+ void setData(const QByteArray &data);
+
+ /**
+ Copy the first \a size bytes of the contents of \a data to the
+ internal buffer replacing all previous contents. This does nothing if
+ isOpen() is true.
+
+ \param data array to copy the data from
+ \param size number of bytes to copy from the array
+ */
+ void setData(const char *data, int size);
+
+ /**
Open the SecureBuffer and set its \a OpenMode to mode.
\param openMode the mode to open the SecureBuffer with
@@ -176,9 +201,9 @@ protected:
qint64 writeData(const char *data, qint64 len);
private:
+ friend class SecureBufferPrivate;
SecureBufferPrivate *d;
- // TODO: does this work?
Q_DISABLE_COPY(SecureBuffer)
};
diff --git a/backend/securebuffer_p.h b/backend/securebuffer_p.h
index 1932ce5..a989bf9 100644
--- a/backend/securebuffer_p.h
+++ b/backend/securebuffer_p.h
@@ -53,15 +53,11 @@ public:
public Q_SLOTS:
void _q_emitSignals() {
- emit bytesWritten(writtenSinceLastEmit);
+ emit q->bytesWritten(writtenSinceLastEmit);
writtenSinceLastEmit = 0;
- emit readyRead();
+ emit q->readyRead();
signalsEmitted = false;
}
-
-Q_SIGNALS:
- void bytesWritten(qint64 len);
- void readyRead();
};
#endif
diff --git a/backend/tests/securebuffertest.cpp b/backend/tests/securebuffertest.cpp
index c9e1e22..6542fba 100644
--- a/backend/tests/securebuffertest.cpp
+++ b/backend/tests/securebuffertest.cpp
@@ -34,6 +34,24 @@ SecureBufferTest::SecureBufferTest()
qRegisterMetaType<QCA::SecureArray>();
}
+// Testing get/set functions
+void SecureBufferTest::getSetCheck()
+{
+ SecureBuffer obj1;
+ // const QByteArray & QBuffer::data()
+ // void QBuffer::setData(const QByteArray &)
+ QByteArray var1("Bogus data");
+ obj1.setData(var1);
+ QCOMPARE(QCA::SecureArray(var1), obj1.data());
+ obj1.setData(QByteArray());
+ QCOMPARE(QCA::SecureArray(), obj1.data());
+ QCA::SecureArray var2("Bogus data");
+ obj1.setData(var2);
+ QCOMPARE(var2, obj1.data());
+ obj1.buffer().fill('x');
+ QVERIFY(var2 != obj1.data());
+}
+
// some status() tests, too
void SecureBufferTest::readBlock()
{
@@ -194,7 +212,7 @@ void SecureBufferTest::writeBlock()
QByteArray data = str.toLatin1();
QCOMPARE(buf.write( data.constData(), data.size() ), qint64(data.size()));
- QCOMPARE(buf.buffer(), QCA::SecureArray(data));
+ QCOMPARE(buf.data(), QCA::SecureArray(data));
}
void SecureBufferTest::seek()
@@ -271,7 +289,7 @@ void SecureBufferTest::seekTest()
QVERIFY(!buf.getChar(&c));
QVERIFY(buf.seek(pos - 1));
QVERIFY(buf.getChar(&c));
- QCOMPARE(c, buf.buffer().at(pos - 1));
+ QCOMPARE(c, buf.data().at(pos - 1));
QVERIFY(buf.seek(pos));
QVERIFY(buf.putChar(c));
}
diff --git a/backend/tests/securebuffertest.h b/backend/tests/securebuffertest.h
index ed7c678..542025e 100644
--- a/backend/tests/securebuffertest.h
+++ b/backend/tests/securebuffertest.h
@@ -40,6 +40,7 @@ public:
SecureBufferTest();
private slots:
+ void getSetCheck();
void readBlock();
void readBlockPastEnd();
void writeBlock_data();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic