summary refs log tree commit diff
path: root/crypto/src/util
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 17:09:32 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 17:09:32 +0700
commit12d3743c290abc58c509312b0ec46994a2811002 (patch)
tree8cf011f381b40602c48cf6f24a363d2f7c87d6ad /crypto/src/util
parentGenerics migration in Pkcs (diff)
downloadBouncyCastle.NET-ed25519-12d3743c290abc58c509312b0ec46994a2811002.tar.xz
Generics migration in Pkix
Diffstat (limited to 'crypto/src/util')
-rw-r--r--crypto/src/util/collections/CollectionUtilities.cs5
-rw-r--r--crypto/src/util/collections/ReadOnlyList.cs57
2 files changed, 62 insertions, 0 deletions
diff --git a/crypto/src/util/collections/CollectionUtilities.cs b/crypto/src/util/collections/CollectionUtilities.cs
index f1d2bac21..4a42cf19d 100644
--- a/crypto/src/util/collections/CollectionUtilities.cs
+++ b/crypto/src/util/collections/CollectionUtilities.cs
@@ -66,6 +66,11 @@ namespace Org.BouncyCastle.Utilities.Collections
             return new UnmodifiableListProxy(l);
         }
 
+        public static IList<T> ReadOnly<T>(IList<T> l)
+        {
+            return new ReadOnlyListProxy<T>(l);
+        }
+
         public static ISet ReadOnly(ISet s)
         {
             return new UnmodifiableSetProxy(s);
diff --git a/crypto/src/util/collections/ReadOnlyList.cs b/crypto/src/util/collections/ReadOnlyList.cs
new file mode 100644
index 000000000..70103022f
--- /dev/null
+++ b/crypto/src/util/collections/ReadOnlyList.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Org.BouncyCastle.Utilities.Collections
+{
+    internal abstract class ReadOnlyList<T>
+        : IList<T>
+    {
+        public T this[int index]
+        {
+            get { return Lookup(index); }
+            set { throw new NotSupportedException(); }
+        }
+
+        IEnumerator IEnumerable.GetEnumerator()
+        {
+            return GetEnumerator();
+        }
+
+        public bool IsReadOnly => true;
+
+        public void Add(T item) => throw new NotSupportedException();
+        public void Clear() => throw new NotSupportedException();
+        public void Insert(int index, T item) => throw new NotSupportedException();
+        public bool Remove(T item) => throw new NotSupportedException();
+        public void RemoveAt(int index) => throw new NotSupportedException();
+
+        public abstract int Count { get; }
+
+        public abstract bool Contains(T item);
+        public abstract void CopyTo(T[] array, int arrayIndex);
+        public abstract IEnumerator<T> GetEnumerator();
+        public abstract int IndexOf(T item);
+
+        protected abstract T Lookup(int index);
+    }
+
+    internal class ReadOnlyListProxy<T>
+        : ReadOnlyList<T>
+    {
+        private readonly IList<T> m_target;
+
+        internal ReadOnlyListProxy(IList<T> target)
+        {
+            m_target = target;
+        }
+
+        public override int Count => m_target.Count;
+        public override bool Contains(T item) => m_target.Contains(item);
+        public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
+        public override IEnumerator<T> GetEnumerator() => m_target.GetEnumerator();
+        public override int IndexOf(T item) => m_target.IndexOf(item);
+
+        protected override T Lookup(int index) => m_target[index];
+    }
+}