blob: db86b22d3fa5c00b7227ab25d682b684402a59fd [file] [log] [blame]
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1Collection.java bcprov-jdk16-145/org/bouncycastle/asn1/ASN1Collection.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1Collection.java 1970-01-01 00:00:00.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/ASN1Collection.java 2011-03-24 03:35:01.000000000 +0000
@@ -0,0 +1,298 @@
+package org.bouncycastle.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.ConcurrentModificationException;
+
+// BEGIN android-note
+/*
+ * This is a new class that was synthesized from ASN1Sequence and
+ * ASN1Set, but with extra smarts about efficiently storing its
+ * elements.
+ */
+// END android-note
+
+/**
+ * Base class for collection-like <code>DERObject</code>s. Instances
+ * of this class will keep up to four elements directly, resorting to
+ * an external collection only if more elements than that need to be
+ * stored.
+ */
+public abstract class ASN1Collection
+ extends ASN1Object
+{
+ /** &gt;= 0; size of the collection */
+ private int size;
+
+ /** null-ok; element #0 */
+ private DEREncodable obj0;
+
+ /** null-ok; element #1 */
+ private DEREncodable obj1;
+
+ /** null-ok; element #2 */
+ private DEREncodable obj2;
+
+ /** null-ok; element #3 */
+ private DEREncodable obj3;
+
+ /** null-ok; elements #4 and higher */
+ private DEREncodable[] rest;
+
+ /**
+ * Returns the object at the postion indicated by index.
+ *
+ * @param index the index (starting at zero) of the object
+ * @return the object at the postion indicated by index
+ */
+ public DEREncodable getObjectAt(int index) {
+ if ((index < 0) || (index >= size)) {
+ throw new IndexOutOfBoundsException(Integer.toString(index));
+ }
+
+ switch (index) {
+ case 0: return obj0;
+ case 1: return obj1;
+ case 2: return obj2;
+ case 3: return obj3;
+ default: return rest[index - 4];
+ }
+ }
+
+ /**
+ * Returns the number of objects in this instance.
+ *
+ * @return the number of objects in this instance
+ */
+ public int size() {
+ return size;
+ }
+
+ /** {@inheritDoc} */
+ public final int hashCode() {
+ Enumeration e = this.getObjects();
+ int hashCode = 0;
+
+ while (e.hasMoreElements()) {
+ Object o = e.nextElement();
+
+ if (o != null) {
+ hashCode ^= o.hashCode();
+ }
+ }
+
+ return hashCode;
+ }
+
+ /**
+ * Adds a new element to this instance.
+ *
+ * @param obj non-null; the instance to add
+ */
+ protected void addObject(DEREncodable obj) {
+ if (obj == null) {
+ throw new NullPointerException("obj == null");
+ }
+
+ int sz = size;
+
+ switch (sz) {
+ case 0: obj0 = obj; break;
+ case 1: obj1 = obj; break;
+ case 2: obj2 = obj; break;
+ case 3: obj3 = obj; break;
+ case 4: {
+ // Initial allocation of rest.
+ rest = new DEREncodable[5];
+ rest[0] = obj;
+ break;
+ }
+ default: {
+ int index = sz - 4;
+ if (index >= rest.length) {
+ // Grow rest.
+ DEREncodable[] newRest = new DEREncodable[index * 2 + 10];
+ System.arraycopy(rest, 0, newRest, 0, rest.length);
+ rest = newRest;
+ }
+ rest[index] = obj;
+ break;
+ }
+ }
+
+ size++;
+ }
+
+ /**
+ * Sets the element at a given index (used by {@link #sort}).
+ *
+ * @param obj non-null; the object to set
+ * @param index &gt;= 0; the index
+ */
+ private void setObjectAt(DEREncodable obj, int index) {
+ switch (index) {
+ case 0: obj0 = obj; break;
+ case 1: obj1 = obj; break;
+ case 2: obj2 = obj; break;
+ case 3: obj3 = obj; break;
+ default: {
+ rest[index - 4] = obj;
+ break;
+ }
+ }
+ }
+
+ /**
+ * Encodes this instance to the given stream.
+ *
+ * @param out non-null; stream to encode to
+ */
+ /*package*/ abstract void encode(DEROutputStream out) throws IOException;
+
+ /**
+ * Gets an enumeration of all the objects in this collection.
+ *
+ * @return non-null; the enumeration
+ */
+ public Enumeration getObjects() {
+ return new ASN1CollectionEnumeration();
+ }
+
+ /**
+ * Associated enumeration class.
+ */
+ private class ASN1CollectionEnumeration implements Enumeration {
+ /** original size; used for modification detection */
+ private final int origSize = size;
+
+ /** &gt;= 0; current cursor */
+ private int at = 0;
+
+ /** {@inheritDoc} */
+ public boolean hasMoreElements() {
+ if (size != origSize) {
+ throw new ConcurrentModificationException();
+ }
+
+ return at < origSize;
+ }
+
+ /** {@inheritDoc} */
+ public Object nextElement() {
+ if (size != origSize) {
+ throw new ConcurrentModificationException();
+ }
+
+ switch (at++) {
+ case 0: return obj0;
+ case 1: return obj1;
+ case 2: return obj2;
+ case 3: return obj3;
+ default: return rest[at - 5];
+ }
+ }
+ }
+
+ /**
+ * Sorts the elements in this instance.
+ */
+ protected void sort() {
+ if (size <= 1) {
+ return;
+ }
+
+ boolean swapped = true;
+
+ // TODO: This is bubble sort. Probably not the best choice.
+ while (swapped) {
+ int index = 0;
+ byte[] a = getEncoded(getObjectAt(0));
+
+ swapped = false;
+
+ while (index != size - 1) {
+ int nextIndex = index + 1;
+ byte[] b = getEncoded(getObjectAt(nextIndex));
+
+ if (lessThanOrEqual(a, b)) {
+ a = b;
+ } else {
+ DEREncodable o = getObjectAt(index);
+
+ setObjectAt(getObjectAt(nextIndex), index);
+ setObjectAt(o, nextIndex);
+
+ swapped = true;
+ }
+
+ index++;
+ }
+ }
+ }
+
+ /**
+ * Returns true if a <= b (arrays are assumed padded with zeros).
+ */
+ private static boolean lessThanOrEqual(byte[] a, byte[] b) {
+ if (a.length <= b.length) {
+ for (int i = 0; i != a.length; i++) {
+ int l = a[i] & 0xff;
+ int r = b[i] & 0xff;
+
+ if (r > l) {
+ return true;
+ } else if (l > r) {
+ return false;
+ }
+ }
+
+ return true;
+ } else {
+ for (int i = 0; i != b.length; i++) {
+ int l = a[i] & 0xff;
+ int r = b[i] & 0xff;
+
+ if (r > l) {
+ return true;
+ } else if (l > r) {
+ return false;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ /**
+ * Gets the encoded form of an object.
+ *
+ * @param obj non-null; object to encode
+ * @return non-null; the encoded form
+ */
+ private static byte[] getEncoded(DEREncodable obj) {
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ ASN1OutputStream aOut = new ASN1OutputStream(bOut);
+
+ try {
+ aOut.writeObject(obj);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(
+ "cannot encode object added to collection");
+ }
+
+ return bOut.toByteArray();
+ }
+
+ /** {@inheritDoc} */
+ public final String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (int i = 0; i < size; i++) {
+ if (i != 0) sb.append(", ");
+ sb.append(getObjectAt(i));
+ }
+ sb.append(']');
+ return sb.toString();
+ }
+}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1InputStream.java bcprov-jdk16-145/org/bouncycastle/asn1/ASN1InputStream.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1InputStream.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/ASN1InputStream.java 2011-03-24 03:35:01.000000000 +0000
@@ -348,7 +348,9 @@
case BMP_STRING:
return new DERBMPString(bytes);
case BOOLEAN:
- return new DERBoolean(bytes);
+ // BEGIN android-changed
+ return DERBoolean.getInstance(bytes);
+ // END android-changed
case ENUMERATED:
return new DEREnumerated(bytes);
case GENERALIZED_TIME:
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1Null.java bcprov-jdk16-145/org/bouncycastle/asn1/ASN1Null.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1Null.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/ASN1Null.java 2011-03-24 03:35:01.000000000 +0000
@@ -8,9 +8,11 @@
public abstract class ASN1Null
extends ASN1Object
{
- public ASN1Null()
+ // BEGIN android-changed
+ /*package*/ ASN1Null()
{
}
+ // END android-changed
public int hashCode()
{
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1Sequence.java bcprov-jdk16-145/org/bouncycastle/asn1/ASN1Sequence.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1Sequence.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/ASN1Sequence.java 2011-03-24 03:35:01.000000000 +0000
@@ -2,12 +2,20 @@
import java.io.IOException;
import java.util.Enumeration;
-import java.util.Vector;
+// BEGIN android-removed
+// import java.util.Vector;
+// END android-removed
+
+// BEGIN android-note
+// Changed inheritence of class.
+// END android-note
public abstract class ASN1Sequence
- extends ASN1Object
+ extends ASN1Collection
{
- private Vector seq = new Vector();
+ // BEGIN android-removed
+ // private Vector seq = new Vector();
+ // END android-removed
/**
* return an ASN1Sequence from the given object.
@@ -85,10 +93,12 @@
throw new IllegalArgumentException("unknown object in getInstance: " + obj.getClass().getName());
}
- public Enumeration getObjects()
- {
- return seq.elements();
- }
+ // BEGIN android-removed
+ // public Enumeration getObjects()
+ // {
+ // return seq.elements();
+ // }
+ // END android-removed
public ASN1SequenceParser parser()
{
@@ -127,45 +137,47 @@
};
}
- /**
- * return the object at the sequence position indicated by index.
- *
- * @param index the sequence number (starting at zero) of the object
- * @return the object at the sequence position indicated by index.
- */
- public DEREncodable getObjectAt(
- int index)
- {
- return (DEREncodable)seq.elementAt(index);
- }
-
- /**
- * return the number of objects in this sequence.
- *
- * @return the number of objects in this sequence.
- */
- public int size()
- {
- return seq.size();
- }
-
- public int hashCode()
- {
- Enumeration e = this.getObjects();
- int hashCode = size();
-
- while (e.hasMoreElements())
- {
- Object o = e.nextElement();
- hashCode *= 17;
- if (o != null)
- {
- hashCode ^= o.hashCode();
- }
- }
-
- return hashCode;
- }
+ // BEGIN android-removed
+ // /**
+ // * return the object at the sequence position indicated by index.
+ // *
+ // * @param index the sequence number (starting at zero) of the object
+ // * @return the object at the sequence position indicated by index.
+ // */
+ // public DEREncodable getObjectAt(
+ // int index)
+ // {
+ // return (DEREncodable)seq.elementAt(index);
+ // }
+ //
+ // /**
+ // * return the number of objects in this sequence.
+ // *
+ // * @return the number of objects in this sequence.
+ // */
+ // public int size()
+ // {
+ // return seq.size();
+ // }
+ //
+ // public int hashCode()
+ // {
+ // Enumeration e = this.getObjects();
+ // int hashCode = size();
+ //
+ // while (e.hasMoreElements())
+ // {
+ // Object o = e.nextElement();
+ // hashCode *= 17;
+ // if (o != null)
+ // {
+ // hashCode ^= o.hashCode();
+ // }
+ // }
+ //
+ // return hashCode;
+ // }
+ // END android-removed
boolean asn1Equals(
DERObject o)
@@ -201,17 +213,19 @@
return true;
}
- protected void addObject(
- DEREncodable obj)
- {
- seq.addElement(obj);
- }
-
- abstract void encode(DEROutputStream out)
- throws IOException;
-
- public String toString()
- {
- return seq.toString();
- }
+ // BEGIN android-removed
+ //protected void addObject(
+ // DEREncodable obj)
+ //{
+ // seq.addElement(obj);
+ //}
+
+ //abstract void encode(DEROutputStream out)
+ // throws IOException;
+
+ //public String toString()
+ //{
+ // return seq.toString();
+ //}
+ // END android-removed
}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1Set.java bcprov-jdk16-145/org/bouncycastle/asn1/ASN1Set.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/ASN1Set.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/ASN1Set.java 2011-03-24 03:35:01.000000000 +0000
@@ -3,12 +3,20 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Enumeration;
-import java.util.Vector;
+// BEGIN android-removed
+// import java.util.Vector;
+// END android-removed
+
+// BEGIN android-note
+// Changed inheritence of class.
+// END android-note
abstract public class ASN1Set
- extends ASN1Object
+ extends ASN1Collection
{
- protected Vector set = new Vector();
+ // BEGIN android-removed
+ // protected Vector set = new Vector();
+ // END android-removed
/**
* return an ASN1Set from the given object.
@@ -104,32 +112,34 @@
{
}
- public Enumeration getObjects()
- {
- return set.elements();
- }
-
- /**
- * return the object at the set position indicated by index.
- *
- * @param index the set number (starting at zero) of the object
- * @return the object at the set position indicated by index.
- */
- public DEREncodable getObjectAt(
- int index)
- {
- return (DEREncodable)set.elementAt(index);
- }
-
- /**
- * return the number of objects in this set.
- *
- * @return the number of objects in this set.
- */
- public int size()
- {
- return set.size();
- }
+ // BEGIN android-removed
+ // public Enumeration getObjects()
+ // {
+ // return set.elements();
+ // }
+ //
+ // /**
+ // * return the object at the set position indicated by index.
+ // *
+ // * @param index the set number (starting at zero) of the object
+ // * @return the object at the set position indicated by index.
+ // */
+ // public DEREncodable getObjectAt(
+ // int index)
+ // {
+ // return (DEREncodable)set.elementAt(index);
+ // }
+ //
+ // /**
+ // * return the number of objects in this set.
+ // *
+ // * @return the number of objects in this set.
+ // */
+ // public int size()
+ // {
+ // return set.size();
+ // }
+ // END android-removed
public ASN1SetParser parser()
{
@@ -168,23 +178,25 @@
};
}
- public int hashCode()
- {
- Enumeration e = this.getObjects();
- int hashCode = size();
-
- while (e.hasMoreElements())
- {
- Object o = e.nextElement();
- hashCode *= 17;
- if (o != null)
- {
- hashCode ^= o.hashCode();
- }
- }
-
- return hashCode;
- }
+ // BEGIN android-removed
+ // public int hashCode()
+ // {
+ // Enumeration e = this.getObjects();
+ // int hashCode = size();
+ //
+ // while (e.hasMoreElements())
+ // {
+ // Object o = e.nextElement();
+ // hashCode *= 17;
+ // if (o != null)
+ // {
+ // hashCode ^= o.hashCode();
+ // }
+ // }
+ //
+ // return hashCode;
+ // }
+ // END android-removed
boolean asn1Equals(
DERObject o)
@@ -220,52 +232,54 @@
return true;
}
- /**
- * return true if a <= b (arrays are assumed padded with zeros).
- */
- private boolean lessThanOrEqual(
- byte[] a,
- byte[] b)
- {
- if (a.length <= b.length)
- {
- for (int i = 0; i != a.length; i++)
- {
- int l = a[i] & 0xff;
- int r = b[i] & 0xff;
-
- if (r > l)
- {
- return true;
- }
- else if (l > r)
- {
- return false;
- }
- }
-
- return true;
- }
- else
- {
- for (int i = 0; i != b.length; i++)
- {
- int l = a[i] & 0xff;
- int r = b[i] & 0xff;
-
- if (r > l)
- {
- return true;
- }
- else if (l > r)
- {
- return false;
- }
- }
-
- return false;
- }
- }
+ // BEGIN android-removed
+ // /**
+ // * return true if a <= b (arrays are assumed padded with zeros).
+ // */
+ // private boolean lessThanOrEqual(
+ // byte[] a,
+ // byte[] b)
+ // {
+ // if (a.length <= b.length)
+ // {
+ // for (int i = 0; i != a.length; i++)
+ // {
+ // int l = a[i] & 0xff;
+ // int r = b[i] & 0xff;
+ //
+ // if (r > l)
+ // {
+ // return true;
+ // }
+ // else if (l > r)
+ // {
+ // return false;
+ // }
+ // }
+ //
+ // return true;
+ // }
+ // else
+ // {
+ // for (int i = 0; i != b.length; i++)
+ // {
+ // int l = a[i] & 0xff;
+ // int r = b[i] & 0xff;
+ //
+ // if (r > l)
+ // {
+ // return true;
+ // }
+ // else if (l > r)
+ // {
+ // return false;
+ // }
+ // }
+ //
+ // return false;
+ // }
+ // }
+ // END android-removed
private byte[] getEncoded(
DEREncodable obj)
@@ -285,59 +299,61 @@
return bOut.toByteArray();
}
- protected void sort()
- {
- if (set.size() > 1)
- {
- boolean swapped = true;
- int lastSwap = set.size() - 1;
-
- while (swapped)
- {
- int index = 0;
- int swapIndex = 0;
- byte[] a = getEncoded((DEREncodable)set.elementAt(0));
-
- swapped = false;
-
- while (index != lastSwap)
- {
- byte[] b = getEncoded((DEREncodable)set.elementAt(index + 1));
-
- if (lessThanOrEqual(a, b))
- {
- a = b;
- }
- else
- {
- Object o = set.elementAt(index);
-
- set.setElementAt(set.elementAt(index + 1), index);
- set.setElementAt(o, index + 1);
-
- swapped = true;
- swapIndex = index;
- }
-
- index++;
- }
-
- lastSwap = swapIndex;
- }
- }
- }
-
- protected void addObject(
- DEREncodable obj)
- {
- set.addElement(obj);
- }
-
- abstract void encode(DEROutputStream out)
- throws IOException;
-
- public String toString()
- {
- return set.toString();
- }
+ // BEGIN android-removed
+ // protected void sort()
+ // {
+ // if (set.size() > 1)
+ // {
+ // boolean swapped = true;
+ // int lastSwap = set.size() - 1;
+ //
+ // while (swapped)
+ // {
+ // int index = 0;
+ // int swapIndex = 0;
+ // byte[] a = getEncoded((DEREncodable)set.elementAt(0));
+ //
+ // swapped = false;
+ //
+ // while (index != lastSwap)
+ // {
+ // byte[] b = getEncoded((DEREncodable)set.elementAt(index + 1));
+ //
+ // if (lessThanOrEqual(a, b))
+ // {
+ // a = b;
+ // }
+ // else
+ // {
+ // Object o = set.elementAt(index);
+ //
+ // set.setElementAt(set.elementAt(index + 1), index);
+ // set.setElementAt(o, index + 1);
+ //
+ // swapped = true;
+ // swapIndex = index;
+ // }
+ //
+ // index++;
+ // }
+ //
+ // lastSwap = swapIndex;
+ // }
+ // }
+ // }
+ //
+ // protected void addObject(
+ // DEREncodable obj)
+ // {
+ // set.addElement(obj);
+ // }
+ //
+ // abstract void encode(DEROutputStream out)
+ // throws IOException;
+ //
+ // public String toString()
+ // {
+ // return set.toString();
+ // }
+ // END android-removed
}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERBoolean.java bcprov-jdk16-145/org/bouncycastle/asn1/DERBoolean.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERBoolean.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/DERBoolean.java 2011-03-24 03:35:01.000000000 +0000
@@ -5,7 +5,9 @@
public class DERBoolean
extends ASN1Object
{
- byte value;
+ // BEGIN android-changed
+ private final byte value;
+ // END android-changed
public static final DERBoolean FALSE = new DERBoolean(false);
public static final DERBoolean TRUE = new DERBoolean(true);
@@ -25,7 +27,9 @@
if (obj instanceof ASN1OctetString)
{
- return new DERBoolean(((ASN1OctetString)obj).getOctets());
+ // BEGIN android-changed
+ return getInstance(((ASN1OctetString)obj).getOctets());
+ // END android-changed
}
if (obj instanceof ASN1TaggedObject)
@@ -45,6 +49,17 @@
return (value ? TRUE : FALSE);
}
+ // BEGIN android-added
+ /**
+ * return a DERBoolean from the passed in array.
+ */
+ public static DERBoolean getInstance(
+ byte[] octets)
+ {
+ return (octets[0] != 0) ? TRUE : FALSE;
+ }
+ // END android-added
+
/**
* return a Boolean from a tagged object.
*
@@ -60,18 +75,22 @@
{
return getInstance(obj.getObject());
}
-
- public DERBoolean(
- byte[] value)
- {
- this.value = value[0];
- }
- public DERBoolean(
+ // BEGIN android-removed
+ //private DERBoolean(
+ // byte[] value)
+ //{
+ // this.value = value[0];
+ //}
+ // END android-removed
+
+ // BEGIN android-changed
+ private DERBoolean(
boolean value)
{
this.value = (value) ? (byte)0xff : (byte)0;
}
+ // END android-changed
public boolean isTrue()
{
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERInputStream.java bcprov-jdk16-145/org/bouncycastle/asn1/DERInputStream.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERInputStream.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/DERInputStream.java 2011-03-24 03:35:01.000000000 +0000
@@ -144,7 +144,9 @@
return new DERConstructedSet(v);
}
case BOOLEAN:
- return new DERBoolean(bytes);
+ // BEGIN android-changed
+ return DERBoolean.getInstance(bytes);
+ // BEGIN android-changed
case INTEGER:
return new DERInteger(bytes);
case ENUMERATED:
@@ -195,7 +197,9 @@
{
if ((tag & CONSTRUCTED) == 0)
{
- return new DERTaggedObject(false, tag & 0x1f, new DERNull());
+ // BEGIN android-changed
+ return new DERTaggedObject(false, tag & 0x1f, DERNull.INSTANCE);
+ // END android-changed
}
else
{
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERNull.java bcprov-jdk16-145/org/bouncycastle/asn1/DERNull.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERNull.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/DERNull.java 2011-03-24 03:35:01.000000000 +0000
@@ -10,9 +10,13 @@
{
public static final DERNull INSTANCE = new DERNull();
- byte[] zeroBytes = new byte[0];
+ // BEGIN android-changed
+ private static final byte[] zeroBytes = new byte[0];
+ // END android-changed
- public DERNull()
+ // BEGIN android-changed
+ protected DERNull()
+ // END android-changed
{
}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERObjectIdentifier.java bcprov-jdk16-145/org/bouncycastle/asn1/DERObjectIdentifier.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERObjectIdentifier.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/DERObjectIdentifier.java 2011-03-24 03:35:01.000000000 +0000
@@ -111,7 +111,13 @@
}
}
- this.identifier = objId.toString();
+ // BEGIN android-changed
+ /*
+ * Intern the identifier so there aren't hundreds of duplicates
+ * (in practice).
+ */
+ this.identifier = objId.toString().intern();
+ // END android-changed
}
public DERObjectIdentifier(
@@ -122,7 +128,13 @@
throw new IllegalArgumentException("string " + identifier + " not an OID");
}
- this.identifier = identifier;
+ // BEGIN android-changed
+ /*
+ * Intern the identifier so there aren't hundreds of duplicates
+ * (in practice).
+ */
+ this.identifier = identifier.intern();
+ // END android-changed
}
public String getId()
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERPrintableString.java bcprov-jdk16-145/org/bouncycastle/asn1/DERPrintableString.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/DERPrintableString.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/DERPrintableString.java 2011-03-24 03:35:01.000000000 +0000
@@ -9,7 +9,9 @@
extends ASN1Object
implements DERString
{
- String string;
+ // BEGIN android-changed
+ private final String string;
+ // END android-changed
/**
* return a printable string from the passed in object.
@@ -66,7 +68,9 @@
cs[i] = (char)(string[i] & 0xff);
}
- this.string = new String(cs);
+ // BEGIN android-changed
+ this.string = new String(cs).intern();
+ // END android-changed
}
/**
@@ -95,7 +99,9 @@
throw new IllegalArgumentException("string contains illegal characters");
}
- this.string = string;
+ // BEGIN android-changed
+ this.string = string.intern();
+ // END android-changed
}
public String getString()
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/OrderedTable.java bcprov-jdk16-145/org/bouncycastle/asn1/OrderedTable.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/OrderedTable.java 1970-01-01 00:00:00.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/OrderedTable.java 2011-03-24 03:35:01.000000000 +0000
@@ -0,0 +1,281 @@
+package org.bouncycastle.asn1;
+
+import java.util.Enumeration;
+import java.util.ConcurrentModificationException;
+
+// BEGIN android-note
+/*
+ * This is a new class that was synthesized from the observed
+ * requirement for a lookup table that preserves order. Since in
+ * practice the element count is typically very low, we just use a
+ * flat list rather than doing any hashing / bucketing.
+ */
+// END android-note
+
+/**
+ * Ordered lookup table. Instances of this class will keep up to four
+ * key-value pairs directly, resorting to an external collection only
+ * if more elements than that need to be stored.
+ */
+public final class OrderedTable {
+ /** null-ok; key #0 */
+ private DERObjectIdentifier key0;
+
+ /** null-ok; key #1 */
+ private DERObjectIdentifier key1;
+
+ /** null-ok; key #2 */
+ private DERObjectIdentifier key2;
+
+ /** null-ok; key #3 */
+ private DERObjectIdentifier key3;
+
+ /** null-ok; value #0 */
+ private Object value0;
+
+ /** null-ok; value #1 */
+ private Object value1;
+
+ /** null-ok; value #2 */
+ private Object value2;
+
+ /** null-ok; value #3 */
+ private Object value3;
+
+ /**
+ * null-ok; array of additional keys and values, alternating
+ * key then value, etc.
+ */
+ private Object[] rest;
+
+ /** &gt;= 0; number of elements in the list */
+ private int size;
+
+ // Note: Default public constructor.
+
+ /**
+ * Adds an element assuming no duplicate key.
+ *
+ * @see #put
+ *
+ * @param key non-null; the key
+ * @param value non-null; the value
+ */
+ public void add(DERObjectIdentifier key, Object value) {
+ if (key == null) {
+ throw new NullPointerException("key == null");
+ }
+
+ if (value == null) {
+ throw new NullPointerException("value == null");
+ }
+
+ int sz = size;
+
+ switch (sz) {
+ case 0: {
+ key0 = key;
+ value0 = value;
+ break;
+ }
+ case 1: {
+ key1 = key;
+ value1 = value;
+ break;
+ }
+ case 2: {
+ key2 = key;
+ value2 = value;
+ break;
+ }
+ case 3: {
+ key3 = key;
+ value3 = value;
+ break;
+ }
+ case 4: {
+ // Do initial allocation of rest.
+ rest = new Object[10];
+ rest[0] = key;
+ rest[1] = value;
+ break;
+ }
+ default: {
+ int index = (sz - 4) * 2;
+ int index1 = index + 1;
+ if (index1 >= rest.length) {
+ // Grow rest.
+ Object[] newRest = new Object[index1 * 2 + 10];
+ System.arraycopy(rest, 0, newRest, 0, rest.length);
+ rest = newRest;
+ }
+ rest[index] = key;
+ rest[index1] = value;
+ break;
+ }
+ }
+
+ size = sz + 1;
+ }
+
+ /**
+ * Gets the number of elements in this instance.
+ */
+ public int size() {
+ return size;
+ }
+
+ /**
+ * Look up the given key, returning the associated value if found.
+ *
+ * @param key non-null; the key to look up
+ * @return null-ok; the associated value
+ */
+ public Object get(DERObjectIdentifier key) {
+ int keyHash = key.hashCode();
+ int sz = size;
+
+ for (int i = 0; i < size; i++) {
+ DERObjectIdentifier probe = getKey(i);
+ if ((probe.hashCode() == keyHash) &&
+ probe.equals(key)) {
+ return getValue(i);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Replace a key if present, otherwise add
+ *
+ * @see #add
+ *
+ * @param key non-null; the key
+ * @param value non-null; the value
+ */
+ public void put(DERObjectIdentifier key, Object value) {
+ if (key == null) {
+ throw new NullPointerException("key == null");
+ }
+
+ if (value == null) {
+ throw new NullPointerException("value == null");
+ }
+
+ int keyHash = key.hashCode();
+ int sz = size;
+
+ for (int i = 0; i < size; i++) {
+ DERObjectIdentifier probe = getKey(i);
+ if ((probe.hashCode() == keyHash) &&
+ probe.equals(key)) {
+ setValue(i, value);
+ return;
+ }
+ }
+
+ add(key, value);
+ }
+
+ /**
+ * Gets the nth key.
+ *
+ * @param n index
+ * @return non-null; the nth key
+ */
+ public DERObjectIdentifier getKey(int n) {
+ if ((n < 0) || (n >= size)) {
+ throw new IndexOutOfBoundsException(Integer.toString(n));
+ }
+
+ switch (n) {
+ case 0: return key0;
+ case 1: return key1;
+ case 2: return key2;
+ case 3: return key3;
+ default: return (DERObjectIdentifier) rest[(n - 4) * 2];
+ }
+ }
+
+ /**
+ * Gets the nth value.
+ *
+ * @param n index
+ * @return non-null; the nth value
+ */
+ public Object getValue(int n) {
+ if ((n < 0) || (n >= size)) {
+ throw new IndexOutOfBoundsException(Integer.toString(n));
+ }
+
+ switch (n) {
+ case 0: return value0;
+ case 1: return value1;
+ case 2: return value2;
+ case 3: return value3;
+ default: return rest[((n - 4) * 2) + 1];
+ }
+ }
+
+ /**
+ * Sets the nth value.
+ *
+ * @param n index
+ * @param value non-null object
+ */
+ public void setValue(int n, Object value) {
+ if ((n < 0) || (n >= size)) {
+ throw new IndexOutOfBoundsException(Integer.toString(n));
+ }
+ if (value == null) {
+ throw new NullPointerException("value == null");
+ }
+
+ switch (n) {
+ case 0: value0 = value; return;
+ case 1: value1 = value; return;
+ case 2: value2 = value; return;
+ case 3: value3 = value; return;
+ default: rest[((n - 4) * 2) + 1] = value; return;
+ }
+ }
+
+ /**
+ * Gets an enumeration of the keys, in order.
+ *
+ * @return non-null; an enumeration of the keys
+ */
+ public Enumeration getKeys() {
+ return new KeyEnumeration();
+ }
+
+ /**
+ * Associated enumeration class.
+ */
+ private class KeyEnumeration implements Enumeration {
+ /** original size; used for modification detection */
+ private final int origSize = size;
+
+ /** &gt;= 0; current cursor */
+ private int at = 0;
+
+ /** {@inheritDoc} */
+ public boolean hasMoreElements() {
+ if (size != origSize) {
+ throw new ConcurrentModificationException();
+ }
+
+ return at < origSize;
+ }
+
+ /** {@inheritDoc} */
+ public Object nextElement() {
+ if (size != origSize) {
+ throw new ConcurrentModificationException();
+ }
+
+ return getKey(at++);
+ }
+ }
+}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java bcprov-jdk16-145/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java 2011-03-24 03:35:01.000000000 +0000
@@ -10,7 +10,10 @@
//
static final String pkcs_1 = "1.2.840.113549.1.1";
static final DERObjectIdentifier rsaEncryption = new DERObjectIdentifier(pkcs_1 + ".1");
- static final DERObjectIdentifier md2WithRSAEncryption = new DERObjectIdentifier(pkcs_1 + ".2");
+ // BEGIN android-removed
+ // Dropping MD2
+ // static final DERObjectIdentifier md2WithRSAEncryption = new DERObjectIdentifier(pkcs_1 + ".2");
+ // END android-removed
static final DERObjectIdentifier md4WithRSAEncryption = new DERObjectIdentifier(pkcs_1 + ".3");
static final DERObjectIdentifier md5WithRSAEncryption = new DERObjectIdentifier(pkcs_1 + ".4");
static final DERObjectIdentifier sha1WithRSAEncryption = new DERObjectIdentifier(pkcs_1 + ".5");
@@ -65,7 +68,10 @@
// md2 OBJECT IDENTIFIER ::=
// {iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) 2}
//
- static final DERObjectIdentifier md2 = new DERObjectIdentifier(digestAlgorithm + ".2");
+ // BEGIN android-removed
+ // Dropping MD2
+ // static final DERObjectIdentifier md2 = new DERObjectIdentifier(digestAlgorithm + ".2");
+ // END android-removed
//
// md4 OBJECT IDENTIFIER ::=
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/pkcs/RSAESOAEPparams.java bcprov-jdk16-145/org/bouncycastle/asn1/pkcs/RSAESOAEPparams.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/pkcs/RSAESOAEPparams.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/pkcs/RSAESOAEPparams.java 2011-03-24 03:35:01.000000000 +0000
@@ -19,7 +19,9 @@
private AlgorithmIdentifier maskGenAlgorithm;
private AlgorithmIdentifier pSourceAlgorithm;
- public final static AlgorithmIdentifier DEFAULT_HASH_ALGORITHM = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, new DERNull());
+ // BEGIN android-changed
+ public final static AlgorithmIdentifier DEFAULT_HASH_ALGORITHM = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
+ // END android-changed
public final static AlgorithmIdentifier DEFAULT_MASK_GEN_FUNCTION = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, DEFAULT_HASH_ALGORITHM);
public final static AlgorithmIdentifier DEFAULT_P_SOURCE_ALGORITHM = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(new byte[0]));
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/pkcs/RSASSAPSSparams.java bcprov-jdk16-145/org/bouncycastle/asn1/pkcs/RSASSAPSSparams.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/pkcs/RSASSAPSSparams.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/pkcs/RSASSAPSSparams.java 2011-03-24 03:35:01.000000000 +0000
@@ -20,7 +20,9 @@
private DERInteger saltLength;
private DERInteger trailerField;
- public final static AlgorithmIdentifier DEFAULT_HASH_ALGORITHM = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, new DERNull());
+ // BEGIN android-changed
+ public final static AlgorithmIdentifier DEFAULT_HASH_ALGORITHM = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
+ // END android-changed
public final static AlgorithmIdentifier DEFAULT_MASK_GEN_FUNCTION = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, DEFAULT_HASH_ALGORITHM);
public final static DERInteger DEFAULT_SALT_LENGTH = new DERInteger(20);
public final static DERInteger DEFAULT_TRAILER_FIELD = new DERInteger(1);
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/util/ASN1Dump.java bcprov-jdk16-145/org/bouncycastle/asn1/util/ASN1Dump.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/util/ASN1Dump.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/util/ASN1Dump.java 2011-03-24 03:35:01.000000000 +0000
@@ -90,7 +90,9 @@
{
Object o = e.nextElement();
- if (o == null || o.equals(new DERNull()))
+ // BEGIN android-changed
+ if (o == null || o.equals(DERNull.INSTANCE))
+ // END android-changed
{
buf.append(tab);
buf.append("NULL");
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/AttCertIssuer.java bcprov-jdk16-145/org/bouncycastle/asn1/x509/AttCertIssuer.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/AttCertIssuer.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/x509/AttCertIssuer.java 2011-03-24 03:35:01.000000000 +0000
@@ -45,7 +45,7 @@
ASN1TaggedObject obj,
boolean explicit)
{
- return getInstance(obj.getObject()); // must be explictly tagged
+ return getInstance(obj.getObject()); // must be explicitly tagged
}
/**
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/BasicConstraints.java bcprov-jdk16-145/org/bouncycastle/asn1/x509/BasicConstraints.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/BasicConstraints.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/x509/BasicConstraints.java 2011-03-24 03:35:01.000000000 +0000
@@ -14,7 +14,9 @@
public class BasicConstraints
extends ASN1Encodable
{
- DERBoolean cA = new DERBoolean(false);
+ // BEGIN android-changed
+ DERBoolean cA = DERBoolean.FALSE;
+ // END android-changed
DERInteger pathLenConstraint = null;
public static BasicConstraints getInstance(
@@ -89,7 +91,9 @@
{
if (cA)
{
- this.cA = new DERBoolean(cA);
+ // BEGIN android-changed
+ this.cA = DERBoolean.getInstance(cA);
+ // END android-changed
this.pathLenConstraint = new DERInteger(pathLenConstraint);
}
else
@@ -104,7 +108,9 @@
{
if (cA)
{
- this.cA = new DERBoolean(true);
+ // BEGIN android-changed
+ this.cA = DERBoolean.TRUE;
+ // END android-changed
}
else
{
@@ -121,7 +127,9 @@
public BasicConstraints(
int pathLenConstraint)
{
- this.cA = new DERBoolean(true);
+ // BEGIN android-changed
+ this.cA = DERBoolean.TRUE;
+ // END android-changed
this.pathLenConstraint = new DERInteger(pathLenConstraint);
}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/IssuingDistributionPoint.java bcprov-jdk16-145/org/bouncycastle/asn1/x509/IssuingDistributionPoint.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/IssuingDistributionPoint.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/x509/IssuingDistributionPoint.java 2011-03-24 03:35:01.000000000 +0000
@@ -96,11 +96,15 @@
}
if (onlyContainsUserCerts)
{
- vec.add(new DERTaggedObject(false, 1, new DERBoolean(true)));
+ // BEGIN android-changed
+ vec.add(new DERTaggedObject(false, 1, DERBoolean.TRUE));
+ // END android-changed
}
if (onlyContainsCACerts)
{
- vec.add(new DERTaggedObject(false, 2, new DERBoolean(true)));
+ // BEGIN android-changed
+ vec.add(new DERTaggedObject(false, 2, DERBoolean.TRUE));
+ // END android-changed
}
if (onlySomeReasons != null)
{
@@ -108,11 +112,15 @@
}
if (indirectCRL)
{
- vec.add(new DERTaggedObject(false, 4, new DERBoolean(true)));
+ // BEGIN android-changed
+ vec.add(new DERTaggedObject(false, 4, DERBoolean.TRUE));
+ // END android-changed
}
if (onlyContainsAttributeCerts)
{
- vec.add(new DERTaggedObject(false, 5, new DERBoolean(true)));
+ // BEGIN android-changed
+ vec.add(new DERTaggedObject(false, 5, DERBoolean.TRUE));
+ // END android-changed
}
seq = new DERSequence(vec);
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/X509Extensions.java bcprov-jdk16-145/org/bouncycastle/asn1/x509/X509Extensions.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/X509Extensions.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/x509/X509Extensions.java 2011-03-24 03:35:01.000000000 +0000
@@ -9,6 +9,9 @@
import org.bouncycastle.asn1.DERObject;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.DERSequence;
+// BEGIN android-added
+import org.bouncycastle.asn1.OrderedTable;
+// END android-added
import java.util.Enumeration;
import java.util.Hashtable;
@@ -172,8 +175,9 @@
*/
public static final DERObjectIdentifier TargetInformation = new DERObjectIdentifier("2.5.29.55");
- private Hashtable extensions = new Hashtable();
- private Vector ordering = new Vector();
+ // BEGIN android-changed
+ private OrderedTable table = new OrderedTable();
+ // END android-changed
public static X509Extensions getInstance(
ASN1TaggedObject obj,
@@ -217,20 +221,26 @@
{
ASN1Sequence s = ASN1Sequence.getInstance(e.nextElement());
- if (s.size() == 3)
+ // BEGIN android-changed
+ int sSize = s.size();
+ DERObjectIdentifier key = (DERObjectIdentifier) s.getObjectAt(0);
+ Object value;
+
+ if (sSize == 3)
{
- extensions.put(s.getObjectAt(0), new X509Extension(DERBoolean.getInstance(s.getObjectAt(1)), ASN1OctetString.getInstance(s.getObjectAt(2))));
+ value = new X509Extension(DERBoolean.getInstance(s.getObjectAt(1)), ASN1OctetString.getInstance(s.getObjectAt(2)));
}
- else if (s.size() == 2)
+ else if (sSize == 2)
{
- extensions.put(s.getObjectAt(0), new X509Extension(false, ASN1OctetString.getInstance(s.getObjectAt(1))));
+ value = new X509Extension(false, ASN1OctetString.getInstance(s.getObjectAt(1)));
}
else
{
- throw new IllegalArgumentException("Bad sequence size: " + s.size());
+ throw new IllegalArgumentException("Bad sequence size: " + sSize);
}
- ordering.addElement(s.getObjectAt(0));
+ table.add(key, value);
+ // END android-changed
}
}
@@ -265,20 +275,14 @@
e = ordering.elements();
}
- while (e.hasMoreElements())
- {
- this.ordering.addElement(e.nextElement());
- }
-
- e = this.ordering.elements();
-
+ // BEGIN android-changed
while (e.hasMoreElements())
{
DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
X509Extension ext = (X509Extension)extensions.get(oid);
-
- this.extensions.put(oid, ext);
+ table.add(oid, ext);
}
+ // END android-changed
}
/**
@@ -293,23 +297,18 @@
{
Enumeration e = objectIDs.elements();
- while (e.hasMoreElements())
- {
- this.ordering.addElement(e.nextElement());
- }
-
+ // BEGIN android-changed
int count = 0;
- e = this.ordering.elements();
-
while (e.hasMoreElements())
{
DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
X509Extension ext = (X509Extension)values.elementAt(count);
- this.extensions.put(oid, ext);
+ table.add(oid, ext);
count++;
}
+ // END android-changed
}
/**
@@ -317,7 +316,9 @@
*/
public Enumeration oids()
{
- return ordering.elements();
+ // BEGIN android-changed
+ return table.getKeys();
+ // END android-changed
}
/**
@@ -329,7 +330,9 @@
public X509Extension getExtension(
DERObjectIdentifier oid)
{
- return (X509Extension)extensions.get(oid);
+ // BEGIN android-changed
+ return (X509Extension)table.get(oid);
+ // END android-changed
}
/**
@@ -345,19 +348,23 @@
public DERObject toASN1Object()
{
ASN1EncodableVector vec = new ASN1EncodableVector();
- Enumeration e = ordering.elements();
+ // BEGIN android-changed
+ int size = table.size();
- while (e.hasMoreElements())
+ for (int i = 0; i < size; i++)
{
- DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
- X509Extension ext = (X509Extension)extensions.get(oid);
+ DERObjectIdentifier oid = table.getKey(i);
+ X509Extension ext = (X509Extension)table.getValue(i);
+ // END android-changed
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(oid);
if (ext.isCritical())
{
- v.add(new DERBoolean(true));
+ // BEGIN android-changed
+ v.add(DERBoolean.TRUE);
+ // END android-changed
}
v.add(ext.getValue());
@@ -371,18 +378,24 @@
public boolean equivalent(
X509Extensions other)
{
- if (extensions.size() != other.extensions.size())
+ // BEGIN android-changed
+ if (table.size() != other.table.size())
+ // END android-changed
{
return false;
}
- Enumeration e1 = extensions.keys();
+ // BEGIN android-changed
+ Enumeration e1 = table.getKeys();
+ // END android-changed
while (e1.hasMoreElements())
{
- Object key = e1.nextElement();
+ // BEGIN android-changed
+ DERObjectIdentifier key = (DERObjectIdentifier)e1.nextElement();
- if (!extensions.get(key).equals(other.extensions.get(key)))
+ if (!table.get(key).equals(other.table.get(key)))
+ // END android-changed
{
return false;
}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/X509Name.java bcprov-jdk16-145/org/bouncycastle/asn1/x509/X509Name.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/X509Name.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/x509/X509Name.java 2011-03-24 03:35:01.000000000 +0000
@@ -247,8 +247,10 @@
*/
public static final Hashtable SymbolLookUp = DefaultLookUp;
- private static final Boolean TRUE = new Boolean(true); // for J2ME compatibility
- private static final Boolean FALSE = new Boolean(false);
+ // BEGIN android-removed
+ //private static final Boolean TRUE = new Boolean(true); // for J2ME compatibility
+ //private static final Boolean FALSE = new Boolean(false);
+ // END android-removed
static
{
@@ -340,9 +342,9 @@
}
private X509NameEntryConverter converter = null;
- private Vector ordering = new Vector();
- private Vector values = new Vector();
- private Vector added = new Vector();
+ // BEGIN android-changed
+ private X509NameElementList elems = new X509NameElementList();
+ // END android-changed
private ASN1Sequence seq;
@@ -403,26 +405,30 @@
throw new IllegalArgumentException("badly sized pair");
}
- ordering.addElement(DERObjectIdentifier.getInstance(s.getObjectAt(0)));
+ // BEGIN android-changed
+ DERObjectIdentifier key = DERObjectIdentifier.getInstance(s.getObjectAt(0));
DEREncodable value = s.getObjectAt(1);
+ String valueStr;
if (value instanceof DERString && !(value instanceof DERUniversalString))
{
String v = ((DERString)value).getString();
if (v.length() > 0 && v.charAt(0) == '#')
{
- values.addElement("\\" + v);
+ valueStr = "\\" + v;
}
else
{
- values.addElement(v);
+ valueStr = v;
}
}
else
{
- values.addElement("#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded())));
+ valueStr = "#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded()));
}
- added.addElement((i != 0) ? TRUE : FALSE); // to allow earlier JDK compatibility
+ boolean added = (i != 0); // to allow earlier JDK compatibility
+ elems.add(key, valueStr, added);
+ // END android-changed
}
}
}
@@ -476,14 +482,23 @@
Hashtable attributes,
X509NameEntryConverter converter)
{
+ // BEGIN android-changed
+ DERObjectIdentifier problem = null;
this.converter = converter;
if (ordering != null)
{
for (int i = 0; i != ordering.size(); i++)
{
- this.ordering.addElement(ordering.elementAt(i));
- this.added.addElement(FALSE);
+ DERObjectIdentifier key =
+ (DERObjectIdentifier) ordering.elementAt(i);
+ String value = (String) attributes.get(key);
+ if (value == null)
+ {
+ problem = key;
+ break;
+ }
+ elems.add(key, value);
}
}
else
@@ -492,22 +507,23 @@
while (e.hasMoreElements())
{
- this.ordering.addElement(e.nextElement());
- this.added.addElement(FALSE);
+ DERObjectIdentifier key =
+ (DERObjectIdentifier) e.nextElement();
+ String value = (String) attributes.get(key);
+ if (value == null)
+ {
+ problem = key;
+ break;
+ }
+ elems.add(key, value);
}
}
- for (int i = 0; i != this.ordering.size(); i++)
+ if (problem != null)
{
- DERObjectIdentifier oid = (DERObjectIdentifier)this.ordering.elementAt(i);
-
- if (attributes.get(oid) == null)
- {
- throw new IllegalArgumentException("No attribute for object id - " + oid.getId() + " - passed to distinguished name");
- }
-
- this.values.addElement(attributes.get(oid)); // copy the hash table
+ throw new IllegalArgumentException("No attribute for object id - " + problem.getId() + " - passed to distinguished name");
}
+ // END android-changed
}
/**
@@ -540,9 +556,10 @@
for (int i = 0; i < oids.size(); i++)
{
- this.ordering.addElement(oids.elementAt(i));
- this.values.addElement(values.elementAt(i));
- this.added.addElement(FALSE);
+ // BEGIN android-changed
+ elems.add((DERObjectIdentifier) oids.elementAt(i),
+ (String) values.elementAt(i));
+ // END android-changed
}
}
@@ -679,7 +696,7 @@
if (index == -1)
{
- throw new IllegalArgumentException("badly formated directory string");
+ throw new IllegalArgumentException("badly formatted directory string");
}
String name = token.substring(0, index);
@@ -691,9 +708,9 @@
X509NameTokenizer vTok = new X509NameTokenizer(value, '+');
String v = vTok.nextToken();
- this.ordering.addElement(oid);
- this.values.addElement(v);
- this.added.addElement(FALSE);
+ // BEGIN android-changed
+ this.elems.add(oid, v);
+ // END android-changed
while (vTok.hasMoreTokens())
{
@@ -702,48 +719,24 @@
String nm = sv.substring(0, ndx);
String vl = sv.substring(ndx + 1);
- this.ordering.addElement(decodeOID(nm, lookUp));
- this.values.addElement(vl);
- this.added.addElement(TRUE);
+ // BEGIN android-changed
+ this.elems.add(decodeOID(nm, lookUp), vl, true);
+ // END android-changed
}
}
else
{
- this.ordering.addElement(oid);
- this.values.addElement(value);
- this.added.addElement(FALSE);
+ // BEGIN android-changed
+ this.elems.add(oid, value);
+ // END android-changed
}
}
if (reverse)
{
- Vector o = new Vector();
- Vector v = new Vector();
- Vector a = new Vector();
-
- int count = 1;
-
- for (int i = 0; i < this.ordering.size(); i++)
- {
- if (((Boolean)this.added.elementAt(i)).booleanValue())
- {
- o.insertElementAt(this.ordering.elementAt(i), count);
- v.insertElementAt(this.values.elementAt(i), count);
- a.insertElementAt(this.added.elementAt(i), count);
- count++;
- }
- else
- {
- o.insertElementAt(this.ordering.elementAt(i), 0);
- v.insertElementAt(this.values.elementAt(i), 0);
- a.insertElementAt(this.added.elementAt(i), 0);
- count = 1;
- }
- }
-
- this.ordering = o;
- this.values = v;
- this.added = a;
+ // BEGIN android-changed
+ this.elems = this.elems.reverse();
+ // END android-changed
}
}
@@ -752,14 +745,17 @@
*/
public Vector getOIDs()
{
+ // BEGIN android-changed
Vector v = new Vector();
+ int size = elems.size();
- for (int i = 0; i != ordering.size(); i++)
+ for (int i = 0; i < size; i++)
{
- v.addElement(ordering.elementAt(i));
+ v.addElement(elems.getKey(i));
}
return v;
+ // END android-changed
}
/**
@@ -769,11 +765,14 @@
public Vector getValues()
{
Vector v = new Vector();
+ // BEGIN android-changed
+ int size = elems.size();
- for (int i = 0; i != values.size(); i++)
+ for (int i = 0; i != size; i++)
{
- v.addElement(values.elementAt(i));
+ v.addElement(elems.getValue(i));
}
+ // END android-changed
return v;
}
@@ -786,12 +785,14 @@
DERObjectIdentifier oid)
{
Vector v = new Vector();
+ int size = elems.size();
+ // BEGIN android-changed
- for (int i = 0; i != values.size(); i++)
+ for (int i = 0; i != size; i++)
{
- if (ordering.elementAt(i).equals(oid))
+ if (elems.getKey(i).equals(oid))
{
- String val = (String)values.elementAt(i);
+ String val = elems.getValue(i);
if (val.length() > 2 && val.charAt(0) == '\\' && val.charAt(1) == '#')
{
@@ -803,6 +804,7 @@
}
}
}
+ // END android-changed
return v;
}
@@ -814,20 +816,23 @@
ASN1EncodableVector vec = new ASN1EncodableVector();
ASN1EncodableVector sVec = new ASN1EncodableVector();
DERObjectIdentifier lstOid = null;
+ // BEGIN android-changed
+ int size = elems.size();
- for (int i = 0; i != ordering.size(); i++)
+ for (int i = 0; i != size; i++)
{
ASN1EncodableVector v = new ASN1EncodableVector();
- DERObjectIdentifier oid = (DERObjectIdentifier)ordering.elementAt(i);
+ DERObjectIdentifier oid = elems.getKey(i);
v.add(oid);
- String str = (String)values.elementAt(i);
+ String str = elems.getValue(i);
v.add(converter.getConvertedValue(oid, str));
if (lstOid == null
- || ((Boolean)this.added.elementAt(i)).booleanValue())
+ || this.elems.getAdded(i))
+ // END android-changed
{
sVec.add(new DERSequence(v));
}
@@ -845,6 +850,7 @@
vec.add(new DERSet(sVec));
seq = new DERSequence(vec);
+ // END android-changed
}
return seq;
@@ -889,22 +895,28 @@
return false;
}
- int orderingSize = ordering.size();
+ // BEGIN android-changed
+ int orderingSize = elems.size();
- if (orderingSize != other.ordering.size())
+ if (orderingSize != other.elems.size())
+ // END android-changed
{
return false;
}
for (int i = 0; i < orderingSize; i++)
{
- DERObjectIdentifier oid = (DERObjectIdentifier)ordering.elementAt(i);
- DERObjectIdentifier oOid = (DERObjectIdentifier)other.ordering.elementAt(i);
+ // BEGIN android-changed
+ DERObjectIdentifier oid = elems.getKey(i);
+ DERObjectIdentifier oOid = other.elems.getKey(i);
+ // END android-changed
if (oid.equals(oOid))
{
- String value = (String)values.elementAt(i);
- String oValue = (String)other.values.elementAt(i);
+ // BEGIN android-changed
+ String value = elems.getValue(i);
+ String oValue = other.elems.getValue(i);
+ // END android-changed
if (!equivalentStrings(value, oValue))
{
@@ -930,9 +942,9 @@
isHashCodeCalculated = true;
// this needs to be order independent, like equals
- for (int i = 0; i != ordering.size(); i += 1)
+ for (int i = 0; i != elems.size(); i += 1)
{
- String value = (String)values.elementAt(i);
+ String value = (String)elems.getValue(i);
value = canonicalize(value);
value = stripInternalSpaces(value);
@@ -976,9 +988,11 @@
return false;
}
- int orderingSize = ordering.size();
+ // BEGIN android-changed
+ int orderingSize = elems.size();
- if (orderingSize != other.ordering.size())
+ if (orderingSize != other.elems.size())
+ // END android-changed
{
return false;
}
@@ -986,7 +1000,9 @@
boolean[] indexes = new boolean[orderingSize];
int start, end, delta;
- if (ordering.elementAt(0).equals(other.ordering.elementAt(0))) // guess forward
+ // BEGIN android-changed
+ if (elems.getKey(0).equals(other.elems.getKey(0))) // guess forward
+ // END android-changed
{
start = 0;
end = orderingSize;
@@ -1002,8 +1018,10 @@
for (int i = start; i != end; i += delta)
{
boolean found = false;
- DERObjectIdentifier oid = (DERObjectIdentifier)ordering.elementAt(i);
- String value = (String)values.elementAt(i);
+ // BEGIN android-changed
+ DERObjectIdentifier oid = elems.getKey(i);
+ String value = elems.getValue(i);
+ // END android-changed
for (int j = 0; j < orderingSize; j++)
{
@@ -1012,11 +1030,15 @@
continue;
}
- DERObjectIdentifier oOid = (DERObjectIdentifier)other.ordering.elementAt(j);
+ // BEGIN android-changed
+ DERObjectIdentifier oOid = other.elems.getKey(j);
+ // END android-changed
if (oid.equals(oOid))
{
- String oValue = (String)other.values.elementAt(j);
+ // BEGIN android-changed
+ String oValue = other.elems.getValue(j);
+ // END android-changed
if (equivalentStrings(value, oValue))
{
@@ -1181,28 +1203,36 @@
StringBuffer ava = null;
- for (int i = 0; i < ordering.size(); i++)
+ // BEGIN android-changed
+ for (int i = 0; i < elems.size(); i++)
+ // END android-changed
{
- if (((Boolean)added.elementAt(i)).booleanValue())
+ if (elems.getAdded(i))
{
ava.append('+');
appendValue(ava, oidSymbols,
- (DERObjectIdentifier)ordering.elementAt(i),
- (String)values.elementAt(i));
+ // BEGIN android-changed
+ elems.getKey(i),
+ elems.getValue(i));
+ // END android-changed
}
else
{
ava = new StringBuffer();
appendValue(ava, oidSymbols,
- (DERObjectIdentifier)ordering.elementAt(i),
- (String)values.elementAt(i));
+ // BEGIN android-changed
+ elems.getKey(i),
+ elems.getValue(i));
+ // END android-changed
components.addElement(ava);
}
}
if (reverse)
{
- for (int i = components.size() - 1; i >= 0; i--)
+ // BEGIN android-changed
+ for (int i = elems.size() - 1; i >= 0; i--)
+ // END android-changed
{
if (first)
{
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/X509NameElementList.java bcprov-jdk16-145/org/bouncycastle/asn1/x509/X509NameElementList.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/X509NameElementList.java 1970-01-01 00:00:00.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/x509/X509NameElementList.java 2011-03-24 03:35:01.000000000 +0000
@@ -0,0 +1,206 @@
+package org.bouncycastle.asn1.x509;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import org.bouncycastle.asn1.DERObjectIdentifier;
+
+// BEGIN android-note
+// This class was extracted from X509Name as a way to keep the element
+// list in a more controlled fashion.
+// END android-note
+
+/**
+ * List of elements of an X509 name. Each element has a key, a value, and
+ * an "added" flag.
+ */
+public class X509NameElementList {
+ /** null-ok; key #0 */
+ private DERObjectIdentifier key0;
+
+ /** null-ok; key #1 */
+ private DERObjectIdentifier key1;
+
+ /** null-ok; key #2 */
+ private DERObjectIdentifier key2;
+
+ /** null-ok; key #3 */
+ private DERObjectIdentifier key3;
+
+ /** null-ok; value #0 */
+ private String value0;
+
+ /** null-ok; value #1 */
+ private String value1;
+
+ /** null-ok; value #2 */
+ private String value2;
+
+ /** null-ok; value #3 */
+ private String value3;
+
+ /**
+ * null-ok; array of additional keys and values, alternating
+ * key then value, etc.
+ */
+ private ArrayList<Object> rest;
+
+ /** bit vector for all the "added" bits */
+ private BitSet added = new BitSet();
+
+ /** &gt;= 0; number of elements in the list */
+ private int size;
+
+ // Note: Default public constructor.
+
+ /**
+ * Adds an element. The "added" flag is set to false for the element.
+ *
+ * @param key non-null; the key
+ * @param value non-null; the value
+ */
+ public void add(DERObjectIdentifier key, String value) {
+ add(key, value, false);
+ }
+
+ /**
+ * Adds an element.
+ *
+ * @param key non-null; the key
+ * @param value non-null; the value
+ * @param added the added bit
+ */
+ public void add(DERObjectIdentifier key, String value, boolean added) {
+ if (key == null) {
+ throw new NullPointerException("key == null");
+ }
+
+ if (value == null) {
+ throw new NullPointerException("value == null");
+ }
+
+ int sz = size;
+
+ switch (sz) {
+ case 0: {
+ key0 = key;
+ value0 = value;
+ break;
+ }
+ case 1: {
+ key1 = key;
+ value1 = value;
+ break;
+ }
+ case 2: {
+ key2 = key;
+ value2 = value;
+ break;
+ }
+ case 3: {
+ key3 = key;
+ value3 = value;
+ break;
+ }
+ case 4: {
+ // Do initial allocation of rest.
+ rest = new ArrayList<Object>();
+ // Fall through...
+ }
+ default: {
+ rest.add(key);
+ rest.add(value);
+ break;
+ }
+ }
+
+ if (added) {
+ this.added.set(sz);
+ }
+
+ size = sz + 1;
+ }
+
+ /**
+ * Sets the "added" flag on the most recently added element.
+ */
+ public void setLastAddedFlag() {
+ added.set(size - 1);
+ }
+
+ /**
+ * Gets the number of elements in this instance.
+ */
+ public int size() {
+ return size;
+ }
+
+ /**
+ * Gets the nth key.
+ *
+ * @param n index
+ * @return non-null; the nth key
+ */
+ public DERObjectIdentifier getKey(int n) {
+ if ((n < 0) || (n >= size)) {
+ throw new IndexOutOfBoundsException(Integer.toString(n));
+ }
+
+ switch (n) {
+ case 0: return key0;
+ case 1: return key1;
+ case 2: return key2;
+ case 3: return key3;
+ default: return (DERObjectIdentifier) rest.get((n - 4) * 2);
+ }
+ }
+
+ /**
+ * Gets the nth value.
+ *
+ * @param n index
+ * @return non-null; the nth value
+ */
+ public String getValue(int n) {
+ if ((n < 0) || (n >= size)) {
+ throw new IndexOutOfBoundsException(Integer.toString(n));
+ }
+
+ switch (n) {
+ case 0: return value0;
+ case 1: return value1;
+ case 2: return value2;
+ case 3: return value3;
+ default: return (String) rest.get(((n - 4) * 2) + 1);
+ }
+ }
+
+ /**
+ * Gets the nth added flag bit.
+ *
+ * @param n index
+ * @return the nth added flag bit
+ */
+ public boolean getAdded(int n) {
+ if ((n < 0) || (n >= size)) {
+ throw new IndexOutOfBoundsException(Integer.toString(n));
+ }
+
+ return added.get(n);
+ }
+
+ /**
+ * Constructs and returns a new instance which consists of the
+ * elements of this one in reverse order
+ *
+ * @return non-null; the reversed instance
+ */
+ public X509NameElementList reverse() {
+ X509NameElementList result = new X509NameElementList();
+
+ for (int i = size - 1; i >= 0; i--) {
+ result.add(getKey(i), getValue(i), getAdded(i));
+ }
+
+ return result;
+ }
+}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/X509NameTokenizer.java bcprov-jdk16-145/org/bouncycastle/asn1/x509/X509NameTokenizer.java
--- bcprov-jdk16-145.orig/org/bouncycastle/asn1/x509/X509NameTokenizer.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/asn1/x509/X509NameTokenizer.java 2011-03-24 03:35:01.000000000 +0000
@@ -58,6 +58,17 @@
}
else
{
+ // BEGIN android-added
+ // copied from a newer version of BouncyCastle
+ if (c == '#' && buf.charAt(buf.length() - 1) == '=')
+ {
+ buf.append('\\');
+ }
+ else if (c == '+' && seperator != '+')
+ {
+ buf.append('\\');
+ }
+ // END android-added
buf.append(c);
}
escaped = false;
@@ -96,4 +107,4 @@
index = end;
return buf.toString().trim();
}
-}
+}
\ No newline at end of file
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/crypto/PBEParametersGenerator.java bcprov-jdk16-145/org/bouncycastle/crypto/PBEParametersGenerator.java
--- bcprov-jdk16-145.orig/org/bouncycastle/crypto/PBEParametersGenerator.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/crypto/PBEParametersGenerator.java 2011-03-24 03:35:00.000000000 +0000
@@ -136,7 +136,8 @@
public static byte[] PKCS12PasswordToBytes(
char[] password)
{
- if (password.length > 0)
+ // BEGIN android-changed
+ if (password != null && password.length > 0)
{
// +1 for extra 2 pad bytes.
byte[] bytes = new byte[(password.length + 1) * 2];
@@ -153,5 +154,6 @@
{
return new byte[0];
}
+ // END android-changed
}
}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/crypto/digests/OpenSSLDigest.java bcprov-jdk16-145/org/bouncycastle/crypto/digests/OpenSSLDigest.java
--- bcprov-jdk16-145.orig/org/bouncycastle/crypto/digests/OpenSSLDigest.java 1970-01-01 00:00:00.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/crypto/digests/OpenSSLDigest.java 2011-03-24 03:35:00.000000000 +0000
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.bouncycastle.crypto.digests;
+
+import org.apache.harmony.xnet.provider.jsse.NativeCrypto;
+import org.bouncycastle.crypto.ExtendedDigest;
+
+/**
+ * Implements the BouncyCastle Digest interface using OpenSSL's EVP API.
+ */
+public class OpenSSLDigest implements ExtendedDigest {
+
+ /**
+ * Holds the standard name of the hashing algorithm, e.g. "SHA-1";
+ */
+ private final String algorithm;
+
+ /**
+ * Holds the OpenSSL name of the hashing algorithm, e.g. "sha1";
+ */
+ private final String openssl;
+
+ /**
+ * Holds a pointer to the native message digest context.
+ */
+ private int ctx;
+
+ /**
+ * Holds a dummy buffer for writing single bytes to the digest.
+ */
+ private final byte[] singleByte = new byte[1];
+
+ /**
+ * Creates a new OpenSSLMessageDigest instance for the given algorithm
+ * name.
+ *
+ * @param algorithm The standard name of the algorithm, e.g. "SHA-1".
+ * @param algorithm The name of the openssl algorithm, e.g. "sha1".
+ */
+ private OpenSSLDigest(String algorithm, String openssl) {
+ this.algorithm = algorithm;
+ this.openssl = openssl;
+ ctx = NativeCrypto.EVP_MD_CTX_create();
+ try {
+ NativeCrypto.EVP_DigestInit(ctx, openssl);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex.getMessage() + " (" + algorithm + ")");
+ }
+ }
+
+ public int doFinal(byte[] out, int outOff) {
+ int i = NativeCrypto.EVP_DigestFinal(ctx, out, outOff);
+ reset();
+ return i;
+ }
+
+ public String getAlgorithmName() {
+ return algorithm;
+ }
+
+ public int getDigestSize() {
+ return NativeCrypto.EVP_MD_CTX_size(ctx);
+ }
+
+ public int getByteLength() {
+ return NativeCrypto.EVP_MD_CTX_block_size(ctx);
+ }
+
+ public void reset() {
+ NativeCrypto.EVP_DigestInit(ctx, openssl);
+ }
+
+ public void update(byte in) {
+ singleByte[0] = in;
+ NativeCrypto.EVP_DigestUpdate(ctx, singleByte, 0, 1);
+ }
+
+ public void update(byte[] in, int inOff, int len) {
+ NativeCrypto.EVP_DigestUpdate(ctx, in, inOff, len);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ NativeCrypto.EVP_MD_CTX_destroy(ctx);
+ ctx = 0;
+ }
+
+ public static class MD5 extends OpenSSLDigest {
+ public MD5() { super("MD5", "md5"); }
+ }
+
+ public static class SHA1 extends OpenSSLDigest {
+ public SHA1() { super("SHA-1", "sha1"); }
+ }
+
+ public static class SHA256 extends OpenSSLDigest {
+ public SHA256() { super("SHA-256", "sha256"); }
+ }
+
+ public static class SHA384 extends OpenSSLDigest {
+ public SHA384() { super("SHA-384", "sha384"); }
+ }
+
+ public static class SHA512 extends OpenSSLDigest {
+ public SHA512() { super("SHA-512", "sha512"); }
+ }
+}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/crypto/engines/RC2Engine.java bcprov-jdk16-145/org/bouncycastle/crypto/engines/RC2Engine.java
--- bcprov-jdk16-145.orig/org/bouncycastle/crypto/engines/RC2Engine.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/crypto/engines/RC2Engine.java 2011-03-24 03:35:00.000000000 +0000
@@ -313,4 +313,4 @@
out[outOff + 6] = (byte)x76;
out[outOff + 7] = (byte)(x76 >> 8);
}
-}
+}
\ No newline at end of file
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/crypto/macs/HMac.java bcprov-jdk16-145/org/bouncycastle/crypto/macs/HMac.java
--- bcprov-jdk16-145.orig/org/bouncycastle/crypto/macs/HMac.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/crypto/macs/HMac.java 2011-03-24 03:35:00.000000000 +0000
@@ -32,23 +32,23 @@
{
blockLengths = new Hashtable();
- blockLengths.put("GOST3411", new Integer(32));
+ blockLengths.put("GOST3411", Integer.valueOf(32));
- blockLengths.put("MD2", new Integer(16));
- blockLengths.put("MD4", new Integer(64));
- blockLengths.put("MD5", new Integer(64));
-
- blockLengths.put("RIPEMD128", new Integer(64));
- blockLengths.put("RIPEMD160", new Integer(64));
-
- blockLengths.put("SHA-1", new Integer(64));
- blockLengths.put("SHA-224", new Integer(64));
- blockLengths.put("SHA-256", new Integer(64));
- blockLengths.put("SHA-384", new Integer(128));
- blockLengths.put("SHA-512", new Integer(128));
+ blockLengths.put("MD2", Integer.valueOf(16));
+ blockLengths.put("MD4", Integer.valueOf(64));
+ blockLengths.put("MD5", Integer.valueOf(64));
+
+ blockLengths.put("RIPEMD128", Integer.valueOf(64));
+ blockLengths.put("RIPEMD160", Integer.valueOf(64));
+
+ blockLengths.put("SHA-1", Integer.valueOf(64));
+ blockLengths.put("SHA-224", Integer.valueOf(64));
+ blockLengths.put("SHA-256", Integer.valueOf(64));
+ blockLengths.put("SHA-384", Integer.valueOf(128));
+ blockLengths.put("SHA-512", Integer.valueOf(128));
- blockLengths.put("Tiger", new Integer(64));
- blockLengths.put("Whirlpool", new Integer(64));
+ blockLengths.put("Tiger", Integer.valueOf(64));
+ blockLengths.put("Whirlpool", Integer.valueOf(64));
}
private static int getByteLength(
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/crypto/signers/RSADigestSigner.java bcprov-jdk16-145/org/bouncycastle/crypto/signers/RSADigestSigner.java
--- bcprov-jdk16-145.orig/org/bouncycastle/crypto/signers/RSADigestSigner.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/crypto/signers/RSADigestSigner.java 2011-03-24 03:35:00.000000000 +0000
@@ -46,8 +46,10 @@
oidMap.put("SHA-384", NISTObjectIdentifiers.id_sha384);
oidMap.put("SHA-512", NISTObjectIdentifiers.id_sha512);
- oidMap.put("MD2", PKCSObjectIdentifiers.md2);
- oidMap.put("MD4", PKCSObjectIdentifiers.md4);
+ // BEGIN android-removed
+ // oidMap.put("MD2", PKCSObjectIdentifiers.md2);
+ // oidMap.put("MD4", PKCSObjectIdentifiers.md4);
+ // END android-removed
oidMap.put("MD5", PKCSObjectIdentifiers.md5);
}
diff -Naur bcprov-jdk16-145.orig/org/bouncycastle/crypto/util/PrivateKeyFactory.java bcprov-jdk16-145/org/bouncycastle/crypto/util/PrivateKeyFactory.java
--- bcprov-jdk16-145.orig/org/bouncycastle/crypto/util/PrivateKeyFactory.java 2010-01-11 21:46:14.000000000 +0000
+++ bcprov-jdk16-145/org/bouncycastle/crypto/util/PrivateKeyFactory.java 2011-03-24 03:35:00.000000000 +0000
@@ -7,31 +7,39 @@
import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.DERObject;
import org.bouncycastle.asn1.DERObjectIdentifier;
-import org.bouncycastle.asn1.nist.NISTNamedCurves;
-import org.bouncycastle.asn1.oiw.ElGamalParameter;
+// BEGIN android-removed
+// import org.bouncycastle.asn1.nist.NISTNamedCurves;
+// import org.bouncycastle.asn1.oiw.ElGamalParameter;
+// END android-removed
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.DHParameter;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.pkcs.RSAPrivateKeyStructure;
-import org.bouncycastle.asn1.sec.ECPrivateKeyStructure;
-import org.bouncycastle.asn1.sec.SECNamedCurves;
-import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
+// BEGIN android-removed
+// import org.bouncycastle.asn1.sec.ECPrivateKeyStructure;
+// import org.bouncycastle.asn1.sec.SECNamedCurves;
+// import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
+// END android-removed
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.DSAParameter;
-import org.bouncycastle.asn1.x9.X962NamedCurves;
-import org.bouncycastle.asn1.x9.X962Parameters;
-import org.bouncycastle.asn1.x9.X9ECParameters;
-import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
+// BEGIN android-removed
+// import org.bouncycastle.asn1.x9.X962NamedCurves;
+// import org.bouncycastle.asn1.x9.X962Parameters;
+// import org.bouncycastle.asn1.x9.X9ECParameters;
+// import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
+// END android-removed
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.DHParameters;
import org.bouncycastle.crypto.params.DHPrivateKeyParameters;
import org.bouncycastle.crypto.params.DSAParameters;
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters;
-import org.bouncycastle.crypto.params.ECDomainParameters;
-import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
-import org.bouncycastle.crypto.params.ElGamalParameters;
-import org.bouncycastle.crypto.params.ElGamalPrivateKeyParameters;
+// BEGIN android-removed
+// import org.bouncycastle.crypto.params.ECDomainParameters;
+// import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
+// import org.bouncycastle.crypto.params.ElGamalParameters;
+// import org.bouncycastle.crypto.params.ElGamalPrivateKeyParameters;
+// END android-removed
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;
import java.io.IOException;
@@ -113,75 +121,77 @@
return new DHPrivateKeyParameters(derX.getValue(), dhParams);
}
- else if (algId.getObjectId().equals(OIWObjectIdentifiers.elGamalAlgorithm))
- {
- ElGamalParameter params = new ElGamalParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
- DERInteger derX = (DERInteger)keyInfo.getPrivateKey();
-
- return new ElGamalPrivateKeyParameters(derX.getValue(), new ElGamalParameters(params.getP(), params.getG()));
- }
- else if (algId.getObjectId().equals(X9ObjectIdentifiers.id_dsa))
- {
- DERInteger derX = (DERInteger)keyInfo.getPrivateKey();
- DEREncodable de = keyInfo.getAlgorithmId().getParameters();
-
- DSAParameters parameters = null;
- if (de != null)
- {
- DSAParameter params = DSAParameter.getInstance(de.getDERObject());
- parameters = new DSAParameters(params.getP(), params.getQ(), params.getG());
- }
-
- return new DSAPrivateKeyParameters(derX.getValue(), parameters);
- }
- else if (algId.getObjectId().equals(X9ObjectIdentifiers.id_ecPublicKey))
- {
- X962Parameters params = new X962Parameters((DERObject)keyInfo.getAlgorithmId().getParameters());
- ECDomainParameters dParams = null;
-
- if (params.isNamedCurve())
- {
- DERObjectIdentifier oid = (DERObjectIdentifier)params.getParameters();
- X9ECParameters ecP = X962NamedCurves.getByOID(oid);
-
- if (ecP == null)
- {
- ecP = SECNamedCurves.getByOID(oid);
-
- if (ecP == null)
- {
- ecP = NISTNamedCurves.getByOID(oid);
-
- if (ecP == null)
- {
- ecP = TeleTrusTNamedCurves.getByOID(oid);
- }
- }
- }
-
- dParams = new ECDomainParameters(
- ecP.getCurve(),
- ecP.getG(),
- ecP.getN(),
- ecP.getH(),
- ecP.getSeed());
- }
- else
- {
- X9ECParameters ecP = new X9ECParameters(
- (ASN1Sequence)params.getParameters());
- dParams = new ECDomainParameters(
- ecP.getCurve(),
- ecP.getG(),
- ecP.getN(),
- ecP.getH(),
- ecP.getSeed());
- }
-
- ECPrivateKeyStructure ec = new ECPrivateKeyStructure((ASN1Sequence)keyInfo.getPrivateKey());
-
- return new ECPrivateKeyParameters(ec.getKey(), dParams);
- }
+ // BEGIN android-removed
+ // else if (algId.getObjectId().equals(OIWObjectIdentifiers.elGamalAlgorithm))
+ // {
+ // ElGamalParameter params = new ElGamalParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
+ // DERInteger derX = (DERInteger)keyInfo.getPrivateKey();
+ //
+ // return new ElGamalPrivateKeyParameters(derX.getValue(), new ElGamalParameters(params.getP(), params.getG()));
+ // }
+ // else if (algId.getObjectId().equals(X9ObjectIdentifiers.id_dsa))