summaryrefslogtreecommitdiff
path: root/bcpkix/src/main/java/org/bouncycastle/cert/dane/DANEEntryStore.java
diff options
context:
space:
mode:
authorSergio Giro <sgiro@google.com>2016-02-01 10:41:58 +0000
committerSergio Giro <sgiro@google.com>2016-02-01 10:41:58 +0000
commit53b61f9fe9d58034fcc7021137e92460f91b70ce (patch)
tree90632062175928181977c1ab3ab59951bc1146c3 /bcpkix/src/main/java/org/bouncycastle/cert/dane/DANEEntryStore.java
parent3eebc2629986481f9fc77ab101c0c9b8ff2f2660 (diff)
downloadbouncycastle-53b61f9fe9d58034fcc7021137e92460f91b70ce.tar.gz
bouncycastle: Android tree with upstream code for version 1.52
Android tree as of 1af9aad12fedf1d93333e19f5ed0ab86f1cc4e2a Change-Id: I714fa0954a5d000cd88d1fb78b0b7fe28246d404
Diffstat (limited to 'bcpkix/src/main/java/org/bouncycastle/cert/dane/DANEEntryStore.java')
-rw-r--r--bcpkix/src/main/java/org/bouncycastle/cert/dane/DANEEntryStore.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/bcpkix/src/main/java/org/bouncycastle/cert/dane/DANEEntryStore.java b/bcpkix/src/main/java/org/bouncycastle/cert/dane/DANEEntryStore.java
new file mode 100644
index 00000000..0d29c80a
--- /dev/null
+++ b/bcpkix/src/main/java/org/bouncycastle/cert/dane/DANEEntryStore.java
@@ -0,0 +1,87 @@
+package org.bouncycastle.cert.dane;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.bouncycastle.util.CollectionStore;
+import org.bouncycastle.util.Selector;
+import org.bouncycastle.util.Store;
+import org.bouncycastle.util.StoreException;
+
+/**
+ * Class storing DANEEntry objects.
+ */
+public class DANEEntryStore
+ implements Store
+{
+ private final Map entries;
+
+ DANEEntryStore(List entries)
+ {
+ Map entryMap = new HashMap();
+
+ for (Iterator it = entries.iterator(); it.hasNext();)
+ {
+ DANEEntry entry = (DANEEntry)it.next();
+
+ entryMap.put(entry.getDomainName(), entry);
+ }
+
+ this.entries = Collections.unmodifiableMap(entryMap);
+ }
+
+ /**
+ * Return a collection of entries matching the passed in selector.
+ *
+ * @param selector the selector to validate entries against.
+ * @return a possibly empty collection of matched entries.
+ * @throws StoreException in case of an underlying issue.
+ */
+ public Collection getMatches(Selector selector)
+ throws StoreException
+ {
+ if (selector == null)
+ {
+ return entries.values();
+ }
+
+ List results = new ArrayList();
+
+ for (Iterator it = entries.values().iterator(); it.hasNext();)
+ {
+ Object next = it.next();
+ if (selector.match(next))
+ {
+ results.add(next);
+ }
+ }
+
+ return Collections.unmodifiableList(results);
+ }
+
+ /**
+ * Return a Store of X509CertificateHolder objects representing all the certificates associated with
+ * entries in the store.
+ *
+ * @return a Store of X509CertificateHolder.
+ */
+ public Store toCertificateStore()
+ {
+ Collection col = this.getMatches(null);
+ List certColl = new ArrayList(col.size());
+
+ for (Iterator it = col.iterator(); it.hasNext();)
+ {
+ DANEEntry entry = (DANEEntry)it.next();
+
+ certColl.add(entry.getCertificate());
+ }
+
+ return new CollectionStore(certColl);
+ }
+}