summaryrefslogtreecommitdiff
path: root/bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java
diff options
context:
space:
mode:
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java59
1 files changed, 26 insertions, 33 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java b/bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java
index ac65d96f..50b8a491 100644
--- a/bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java
+++ b/bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java
@@ -3,8 +3,8 @@ package org.bouncycastle.asn1;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.bouncycastle.util.Arrays;
@@ -20,9 +20,10 @@ public class ASN1ObjectIdentifier
/**
* return an OID from the passed in object
+ *
* @param obj an ASN1ObjectIdentifier or an object that can be converted into one.
- * @throws IllegalArgumentException if the object cannot be converted.
* @return an ASN1ObjectIdentifier instance, or null.
+ * @throws IllegalArgumentException if the object cannot be converted.
*/
public static ASN1ObjectIdentifier getInstance(
Object obj)
@@ -59,9 +60,9 @@ public class ASN1ObjectIdentifier
* @param obj the tagged object holding the object we want
* @param explicit true if the object is meant to be explicitly
* tagged false otherwise.
+ * @return an ASN1ObjectIdentifier instance, or null.
* @throws IllegalArgumentException if the tagged object cannot
* be converted.
- * @return an ASN1ObjectIdentifier instance, or null.
*/
public static ASN1ObjectIdentifier getInstance(
ASN1TaggedObject obj,
@@ -190,12 +191,12 @@ public class ASN1ObjectIdentifier
// END android-changed
}
- /**
- * Create an OID that creates a branch under the current one.
- *
- * @param branchID node numbers for the new branch.
- * @return the OID for the new created branch.
- */
+ /**
+ * Create an OID that creates a branch under the current one.
+ *
+ * @param branchID node numbers for the new branch.
+ * @return the OID for the new created branch.
+ */
ASN1ObjectIdentifier(ASN1ObjectIdentifier oid, String branchID)
{
if (!isValidBranchID(branchID, 0))
@@ -428,32 +429,29 @@ public class ASN1ObjectIdentifier
* The pool is also used by the ASN.1 parsers to limit the number of duplicated OID
* objects in circulation.
* </p>
+ *
* @return a reference to the identifier in the pool.
*/
public ASN1ObjectIdentifier intern()
{
- synchronized (pool)
+ final OidHandle hdl = new OidHandle(getBody());
+ ASN1ObjectIdentifier oid = pool.get(hdl);
+ if (oid == null)
{
- OidHandle hdl = new OidHandle(getBody());
- ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)pool.get(hdl);
-
- if (oid != null)
- {
- return oid;
- }
- else
+ oid = pool.putIfAbsent(hdl, this);
+ if (oid == null)
{
- pool.put(hdl, this);
- return this;
+ oid = this;
}
}
+ return oid;
}
- private static final Map pool = new HashMap();
+ private static final ConcurrentMap<OidHandle, ASN1ObjectIdentifier> pool = new ConcurrentHashMap<OidHandle, ASN1ObjectIdentifier>();
private static class OidHandle
{
- private int key;
+ private final int key;
private final byte[] enc;
OidHandle(byte[] enc)
@@ -480,17 +478,12 @@ public class ASN1ObjectIdentifier
static ASN1ObjectIdentifier fromOctetString(byte[] enc)
{
- OidHandle hdl = new OidHandle(enc);
-
- synchronized (pool)
+ final OidHandle hdl = new OidHandle(enc);
+ ASN1ObjectIdentifier oid = pool.get(hdl);
+ if (oid == null)
{
- ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)pool.get(hdl);
- if (oid != null)
- {
- return oid;
- }
+ return new ASN1ObjectIdentifier(enc);
}
-
- return new ASN1ObjectIdentifier(enc);
+ return oid;
}
}