summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.xml3
-rw-r--r--src/com/isode/stroke/base/ByteArray.java39
-rw-r--r--src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java1
-rw-r--r--src/com/isode/stroke/stringcodecs/HMACSHA1.java2
-rw-r--r--src/com/isode/stroke/stringcodecs/PBKDF2.java1
5 files changed, 26 insertions, 20 deletions
diff --git a/build.xml b/build.xml
index 820b482..94ef93b 100644
--- a/build.xml
+++ b/build.xml
@@ -15,9 +15,10 @@
<property name="main-class" value="com.isode.stroke.examples.gui.StrokeGUI"/>
<property name="compile.debug" value="true"/>
<property name="testsuiteclass" value="com.isode.stroke.unittest.StrokeTestSuite" />
+ <property name="xpp-dir" value="../third-party/xpp"/>
<path id="classpath">
- <fileset dir="../third-party/xpp" includes="xpp.jar"/>
+ <fileset dir="${xpp-dir}" includes="xpp.jar"/>
</path>
<target name="init">
<tstamp/>
diff --git a/src/com/isode/stroke/base/ByteArray.java b/src/com/isode/stroke/base/ByteArray.java
index a36e305..a715d36 100644
--- a/src/com/isode/stroke/base/ByteArray.java
+++ b/src/com/isode/stroke/base/ByteArray.java
@@ -10,6 +10,7 @@
package com.isode.stroke.base;
import java.io.UnsupportedEncodingException;
+import java.util.Vector;
/**
*
@@ -36,8 +37,8 @@ public class ByteArray {
}
private void fromBytes(final byte[] b) {
- data_ = new byte[b.length];
- System.arraycopy(b, 0, data_, 0, b.length);
+ clear();
+ append(b);
}
/*public ByteArray(char[] c, int n) {
@@ -47,15 +48,20 @@ public class ByteArray {
}*/
/**
- * These are the raw, modifyable data!
- * @return
+ * @return array copy of internal data.
*/
public byte[] getData() {
- return data_;
+ if (dataCopy_ == null) {
+ dataCopy_ = new byte[getSize()];
+ for (int i = 0; i < data_.size(); i++) {
+ dataCopy_[i] = data_.get(i);
+ }
+ }
+ return dataCopy_;
}
public int getSize() {
- return data_.length;
+ return data_.size();
}
public boolean isEmpty() {
@@ -87,22 +93,16 @@ public class ByteArray {
/** Mutable add */
private ByteArray append(byte[] b) {
- int newLength = data_.length + b.length;
- byte[] newData = new byte[newLength];
- for (int i = 0; i < data_.length; i++) {
- newData[i] = data_[i];
- }
for (int i = 0; i < b.length; i++) {
- newData[i + data_.length] = b[i];
+ append(b[i]);
}
- data_ = newData;
return this;
}
/** Mutable add */
public ByteArray append(byte b) {
- byte[] bytes = {b};
- append(bytes);
+ dataCopy_ = null; /* Invalidate cache */
+ data_.add(b);
return this;
}
@@ -144,7 +144,7 @@ public class ByteArray {
@Override
public String toString() {
try {
- return new String(data_, "UTF-8");
+ return new String(getData(), "UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new IllegalStateException("JVM has no 'UTF-8' encoding");
}
@@ -155,8 +155,9 @@ public class ByteArray {
}
public void clear() {
- data_ = new byte[]{};
+ data_ = new Vector<Byte>();
+ dataCopy_ = null;
}
- private byte[] data_ = {};
-
+ Vector<Byte> data_ = new Vector<Byte>();
+ byte[] dataCopy_ = null;
}
diff --git a/src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java b/src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java
index da44d85..09a3ac7 100644
--- a/src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java
+++ b/src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java
@@ -60,6 +60,7 @@ public class SCRAMSHA1ClientAuthenticator extends ClientAuthenticator {
for (int i = 0; i < clientProofData.length; ++i) {
clientProofData[i] ^= clientSignature.getData()[i];
}
+ clientProof = new ByteArray(clientProofData);
ByteArray result = getFinalMessageWithoutProof().append(",p=").append(Base64.encode(clientProof));
return result;
} else {
diff --git a/src/com/isode/stroke/stringcodecs/HMACSHA1.java b/src/com/isode/stroke/stringcodecs/HMACSHA1.java
index 1d8c9b7..8d3f5c5 100644
--- a/src/com/isode/stroke/stringcodecs/HMACSHA1.java
+++ b/src/com/isode/stroke/stringcodecs/HMACSHA1.java
@@ -34,6 +34,7 @@ public class HMACSHA1 {
for (int i = 0; i < xInner.length; ++i) {
xInner[i] ^= 0x36;
}
+ x = new ByteArray(xInner);
x.append(data);
// Create the second value
@@ -42,6 +43,7 @@ public class HMACSHA1 {
for (int i = 0; i < yInner.length; ++i) {
yInner[i] ^= 0x5c;
}
+ y = new ByteArray(yInner);
y.append(SHA1.getHash(x));
return SHA1.getHash(y);
diff --git a/src/com/isode/stroke/stringcodecs/PBKDF2.java b/src/com/isode/stroke/stringcodecs/PBKDF2.java
index 547cbec..8e1a28e 100644
--- a/src/com/isode/stroke/stringcodecs/PBKDF2.java
+++ b/src/com/isode/stroke/stringcodecs/PBKDF2.java
@@ -24,6 +24,7 @@ public class PBKDF2 {
}
++i;
}
+ result = new ByteArray(resultData);
return result;
}
}