diff options
author | Oren Novotny <oren@novotny.org> | 2015-10-27 11:08:16 -0400 |
---|---|---|
committer | Oren Novotny <oren@novotny.org> | 2015-10-27 11:08:16 -0400 |
commit | 6edc6eb31eb49bd710c1417690a8370729141ec5 (patch) | |
tree | 0c8bc587be14be0fb1bddfd72c568386fac6e9da /crypto/src/asn1 | |
parent | Merge branch 'master' into master-vs12 (diff) | |
parent | Pull a few PORTABLE changes from BouncyCastle-PCL (with fixes) (diff) | |
download | BouncyCastle.NET-ed25519-6edc6eb31eb49bd710c1417690a8370729141ec5.tar.xz |
Merge branch 'master' into master-vs12
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r-- | crypto/src/asn1/Asn1Set.cs | 29 |
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) { |