From c1e603f741728fd570e30c46eb20ef8dfb23238a Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 27 Oct 2015 12:30:28 +0700 Subject: Pull a few PORTABLE changes from BouncyCastle-PCL (with fixes) --- crypto/src/asn1/Asn1Set.cs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'crypto/src/asn1/Asn1Set.cs') 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() + .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 + { + 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) { -- cgit 1.4.1