summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-19 19:25:56 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-19 19:25:56 (GMT)
commite9bdc38536488b76e5e3a715961a94085302cc15 (patch)
tree57dd253c436a3419152e568be902dab5ad99fc51 /Swiften/Base/ByteArray.h
parentb2a55163964c835a4b0b61af0f0d959ec58a5a0e (diff)
downloadswift-e9bdc38536488b76e5e3a715961a94085302cc15.zip
swift-e9bdc38536488b76e5e3a715961a94085302cc15.tar.bz2
Added HMAC-SHA1 and SCRAM-SHA1 implementations.
We don't authenticate with SCRAM-SHA1 yet.
Diffstat (limited to 'Swiften/Base/ByteArray.h')
-rw-r--r--Swiften/Base/ByteArray.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/Swiften/Base/ByteArray.h b/Swiften/Base/ByteArray.h
index ea96d09..ab256a4 100644
--- a/Swiften/Base/ByteArray.h
+++ b/Swiften/Base/ByteArray.h
@@ -11,86 +11,93 @@ namespace Swift {
{
public:
typedef std::vector<char>::const_iterator const_iterator;
ByteArray() : data_() {}
ByteArray(const String& s) : data_(s.getUTF8String().begin(), s.getUTF8String().end()) {}
ByteArray(const char* c) {
while (*c) {
data_.push_back(*c);
++c;
}
}
ByteArray(const char* c, size_t n) {
if (n > 0) {
data_.resize(n);
memcpy(&data_[0], c, n);
}
}
const char* getData() const {
return data_.empty() ? NULL : &data_[0];
}
char* getData() {
return data_.empty() ? NULL : &data_[0];
}
size_t getSize() const {
return data_.size();
}
bool isEmpty() const {
return data_.empty();
}
void resize(size_t size) {
return data_.resize(size);
}
friend ByteArray operator+(const ByteArray& a, const ByteArray&b) {
ByteArray result(a);
result.data_.insert(result.data_.end(), b.data_.begin(), b.data_.end());
return result;
}
+ friend ByteArray operator+(const ByteArray& a, char b) {
+ ByteArray x;
+ x.resize(1);
+ x[0] = b;
+ return a + x;
+ }
+
ByteArray& operator+=(const ByteArray& b) {
data_.insert(data_.end(), b.data_.begin(), b.data_.end());
return *this;
}
friend bool operator==(const ByteArray& a, const ByteArray& b) {
return a.data_ == b.data_;
}
const char& operator[](size_t i) const {
return data_[i];
}
char& operator[](size_t i) {
return data_[i];
}
const_iterator begin() const {
return data_.begin();
}
const_iterator end() const {
return data_.end();
}
String toString() const {
return String(getData(), getSize());
}
void readFromFile(const String& file);
private:
std::vector<char> data_;
};
}
std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s);