summary refs log tree commit diff
path: root/crypto/src/asn1
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-10-27 12:30:28 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-10-27 12:30:28 +0700
commitc1e603f741728fd570e30c46eb20ef8dfb23238a (patch)
tree6c9e55973cd64b4f6ba5d12fcc2414aa41b14729 /crypto/src/asn1
parentExclude some tests for PORTABLE (diff)
downloadBouncyCastle.NET-ed25519-c1e603f741728fd570e30c46eb20ef8dfb23238a.tar.xz
Pull a few PORTABLE changes from BouncyCastle-PCL (with fixes)
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r--crypto/src/asn1/Asn1Set.cs29
1 files changed, 28 insertions, 1 deletions
diff --git a/crypto/src/asn1/Asn1Set.cs b/crypto/src/asn1/Asn1Set.cs

index cf039d7fe..18f8020f2 100644 --- a/crypto/src/asn1/Asn1Set.cs +++ b/crypto/src/asn1/Asn1Set.cs
@@ -2,6 +2,11 @@ using System; using System.Collections; using System.IO; +#if PORTABLE +using System.Collections.Generic; +using System.Linq; +#endif + using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Collections; @@ -283,6 +288,18 @@ namespace Org.BouncyCastle.Asn1 if (_set.Count < 2) return; +#if PORTABLE + var sorted = _set.Cast<Asn1Encodable>() + .Select(a => new { Item = a, Key = a.GetEncoded(Asn1Encodable.Der) }) + .OrderBy(t => t.Key, new DerComparer()) + .Select(t => t.Item) + .ToList(); + + for (int i = 0; i < _set.Count; ++i) + { + _set[i] = sorted[i]; + } +#else Asn1Encodable[] items = new Asn1Encodable[_set.Count]; byte[][] keys = new byte[_set.Count][]; @@ -299,6 +316,7 @@ namespace Org.BouncyCastle.Asn1 { _set[i] = items[i]; } +#endif } protected internal void AddObject(Asn1Encodable obj) @@ -311,12 +329,21 @@ namespace Org.BouncyCastle.Asn1 return CollectionUtilities.ToString(_set); } +#if PORTABLE + private class DerComparer + : IComparer<byte[]> + { + public int Compare(byte[] x, byte[] y) + { + byte[] a = x, b = y; +#else private class DerComparer - : IComparer + : IComparer { public int Compare(object x, object y) { byte[] a = (byte[])x, b = (byte[])y; +#endif int len = System.Math.Min(a.Length, b.Length); for (int i = 0; i != len; ++i) {