diff options
author | Sergio Giro <sgiro@google.com> | 2017-01-19 21:40:17 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-01-19 21:40:17 +0000 |
commit | fbf7512c8942075f80cba53e708c13682f04ea29 (patch) | |
tree | 8ebc72ead6f9a80938fdba92e217da96ee451037 /bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java | |
parent | e54ca62fe13a7f6a52a89e409edcf4b6547072be (diff) | |
parent | 07a37e800ceaa1470036078af8d69981604e0945 (diff) | |
download | bouncycastle-fbf7512c8942075f80cba53e708c13682f04ea29.tar.gz |
Merge "bouncycastle: upgrade to version 1.56" am: ae9dc88d85 am: ed012da722
am: 07a37e800c
Change-Id: Ie6a51b57d83037f0f7f1acecedc16da1c1bd6820
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java')
-rw-r--r-- | bcprov/src/main/java/org/bouncycastle/asn1/ASN1ObjectIdentifier.java | 59 |
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; } } |