Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2013-05-15 16:24:36 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2013-05-15 16:24:36 +0400
commit162ed2baf9cba9921148f29a106574e8256ef90b (patch)
tree8acedfab92c4c7a4596d60f3da85a19c23cdf9fe
parentcfeb6a4b3acacf607c0fe48d9553c612f3298898 (diff)
Refactor getRecipients method
-rw-r--r--src/main/java/org/bouncycastle/cms/RecipientInformationStore.java236
1 files changed, 115 insertions, 121 deletions
diff --git a/src/main/java/org/bouncycastle/cms/RecipientInformationStore.java b/src/main/java/org/bouncycastle/cms/RecipientInformationStore.java
index 7b8f57a8..af1ffe06 100644
--- a/src/main/java/org/bouncycastle/cms/RecipientInformationStore.java
+++ b/src/main/java/org/bouncycastle/cms/RecipientInformationStore.java
@@ -1,121 +1,115 @@
-package org.bouncycastle.cms;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-public class RecipientInformationStore
-{
- private final List all; //ArrayList[RecipientInformation]
- private final Map table = new HashMap(); // HashMap[RecipientID, ArrayList[RecipientInformation]]
-
- public RecipientInformationStore(
- Collection recipientInfos)
- {
- Iterator it = recipientInfos.iterator();
-
- while (it.hasNext())
- {
- RecipientInformation recipientInformation = (RecipientInformation)it.next();
- RecipientId rid = recipientInformation.getRID();
-
- List list = (ArrayList)table.get(rid);
- if (list == null)
- {
- list = new ArrayList(1);
- table.put(rid, list);
- }
-
- list.add(recipientInformation);
- }
-
- this.all = new ArrayList(recipientInfos);
- }
-
- /**
- * Return the first RecipientInformation object that matches the
- * passed in selector. Null if there are no matches.
- *
- * @param selector to identify a recipient
- * @return a single RecipientInformation object. Null if none matches.
- */
- public RecipientInformation get(
- RecipientId selector)
- {
- Collection list = getRecipients(selector);
-
- return list.size() == 0 ? null : (RecipientInformation)list.iterator().next();
- }
-
- /**
- * Return the number of recipients in the collection.
- *
- * @return number of recipients identified.
- */
- public int size()
- {
- return all.size();
- }
-
- /**
- * Return all recipients in the collection
- *
- * @return a collection of recipients.
- */
- public Collection getRecipients()
- {
- return new ArrayList(all);
- }
-
- /**
- * Return possible empty collection with recipients matching the passed in RecipientId
- *
- * @param selector a recipient id to select against.
- * @return a collection of RecipientInformation objects.
- */
- public Collection getRecipients(
- RecipientId selector)
- {
- if (selector instanceof KeyTransRecipientId)
- {
- KeyTransRecipientId keyTrans = (KeyTransRecipientId)selector;
- byte[] subjectKeyId = keyTrans.getSubjectKeyIdentifier();
-
- if (keyTrans.getIssuer() != null && subjectKeyId != null)
- {
- List results = new ArrayList();
-
- Collection match1 = getRecipients(new KeyTransRecipientId(keyTrans.getIssuer(), keyTrans.getSerialNumber()));
-
- if (match1 != null)
- {
- results.addAll(match1);
- }
-
- Collection match2 = getRecipients(new KeyTransRecipientId(subjectKeyId));
-
- if (match2 != null)
- {
- results.addAll(match2);
- }
-
- return results;
- }
- else
- {
- List list = (ArrayList)table.get(selector);
-
- return list == null ? new ArrayList() : new ArrayList(list);
- }
- }
- else
- {
- List list = (ArrayList)table.get(selector);
-
- return list == null ? new ArrayList() : new ArrayList(list);
- }
- }
-}
+package org.bouncycastle.cms;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.bouncycastle.asn1.x500.X500Name;
+
+public class RecipientInformationStore
+{
+ private final List all; //ArrayList[RecipientInformation]
+ private final Map table = new HashMap(); // HashMap[RecipientID, ArrayList[RecipientInformation]]
+
+ public RecipientInformationStore(
+ Collection recipientInfos)
+ {
+ Iterator it = recipientInfos.iterator();
+
+ while (it.hasNext())
+ {
+ RecipientInformation recipientInformation = (RecipientInformation)it.next();
+ RecipientId rid = recipientInformation.getRID();
+
+ List list = (ArrayList)table.get(rid);
+ if (list == null)
+ {
+ list = new ArrayList(1);
+ table.put(rid, list);
+ }
+
+ list.add(recipientInformation);
+ }
+
+ this.all = new ArrayList(recipientInfos);
+ }
+
+ /**
+ * Return the first RecipientInformation object that matches the
+ * passed in selector. Null if there are no matches.
+ *
+ * @param selector to identify a recipient
+ * @return a single RecipientInformation object. Null if none matches.
+ */
+ public RecipientInformation get(
+ RecipientId selector)
+ {
+ Collection list = getRecipients(selector);
+
+ return list.size() == 0 ? null : (RecipientInformation)list.iterator().next();
+ }
+
+ /**
+ * Return the number of recipients in the collection.
+ *
+ * @return number of recipients identified.
+ */
+ public int size()
+ {
+ return all.size();
+ }
+
+ /**
+ * Return all recipients in the collection
+ *
+ * @return a collection of recipients.
+ */
+ public Collection getRecipients()
+ {
+ return new ArrayList(all);
+ }
+
+ /**
+ * Return possible empty collection with recipients matching the passed in RecipientId
+ *
+ * @param selector a recipient id to select against.
+ * @return a collection of RecipientInformation objects.
+ */
+ public Collection getRecipients(
+ RecipientId selector)
+ {
+ if (selector instanceof KeyTransRecipientId)
+ {
+ KeyTransRecipientId keyTrans = (KeyTransRecipientId)selector;
+
+ X500Name issuer = keyTrans.getIssuer();
+ byte[] subjectKeyId = keyTrans.getSubjectKeyIdentifier();
+
+ if (issuer != null && subjectKeyId != null)
+ {
+ List results = new ArrayList();
+
+ Collection match1 = getRecipients(new KeyTransRecipientId(issuer, keyTrans.getSerialNumber()));
+ if (match1 != null)
+ {
+ results.addAll(match1);
+ }
+
+ Collection match2 = getRecipients(new KeyTransRecipientId(subjectKeyId));
+ if (match2 != null)
+ {
+ results.addAll(match2);
+ }
+
+ return results;
+ }
+ }
+
+ List list = (ArrayList)table.get(selector);
+
+ return list == null ? new ArrayList() : new ArrayList(list);
+ }
+}