Arrays.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Text;
  5. using BestHTTP.PlatformSupport.Memory;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
  8. {
  9. /// <summary> General array utilities.</summary>
  10. [BestHTTP.PlatformSupport.IL2CPP.Il2CppSetOption(BestHTTP.PlatformSupport.IL2CPP.Option.NullChecks, false)]
  11. [BestHTTP.PlatformSupport.IL2CPP.Il2CppSetOption(BestHTTP.PlatformSupport.IL2CPP.Option.ArrayBoundsChecks, false)]
  12. [BestHTTP.PlatformSupport.IL2CPP.Il2CppSetOption(BestHTTP.PlatformSupport.IL2CPP.Option.DivideByZeroChecks, false)]
  13. [BestHTTP.PlatformSupport.IL2CPP.Il2CppEagerStaticClassConstructionAttribute]
  14. public abstract class Arrays
  15. {
  16. public static readonly byte[] EmptyBytes = new byte[0];
  17. public static readonly int[] EmptyInts = new int[0];
  18. public static bool AreAllZeroes(byte[] buf, int off, int len)
  19. {
  20. uint bits = 0;
  21. for (int i = 0; i < len; ++i)
  22. {
  23. bits |= buf[off + i];
  24. }
  25. return bits == 0;
  26. }
  27. public static bool AreEqual(
  28. bool[] a,
  29. bool[] b)
  30. {
  31. if (a == b)
  32. return true;
  33. if (a == null || b == null)
  34. return false;
  35. return HaveSameContents(a, b);
  36. }
  37. public static bool AreEqual(
  38. char[] a,
  39. char[] b)
  40. {
  41. if (a == b)
  42. return true;
  43. if (a == null || b == null)
  44. return false;
  45. return HaveSameContents(a, b);
  46. }
  47. /// <summary>
  48. /// Are two arrays equal.
  49. /// </summary>
  50. /// <param name="a">Left side.</param>
  51. /// <param name="b">Right side.</param>
  52. /// <returns>True if equal.</returns>
  53. public static bool AreEqual(byte[] a, byte[] b)
  54. {
  55. if (a == b)
  56. return true;
  57. if (a == null || b == null)
  58. return false;
  59. return HaveSameContents(a, b);
  60. }
  61. public static bool AreEqual(byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)
  62. {
  63. int aLength = aToIndex - aFromIndex;
  64. int bLength = bToIndex - bFromIndex;
  65. if (aLength != bLength)
  66. return false;
  67. for (int i = 0; i < aLength; ++i)
  68. {
  69. if (a[aFromIndex + i] != b[bFromIndex + i])
  70. return false;
  71. }
  72. return true;
  73. }
  74. public static bool AreSame(
  75. byte[] a,
  76. byte[] b)
  77. {
  78. return AreEqual(a, b);
  79. }
  80. /// <summary>
  81. /// A constant time equals comparison - does not terminate early if
  82. /// test will fail.
  83. /// </summary>
  84. /// <param name="a">first array</param>
  85. /// <param name="b">second array</param>
  86. /// <returns>true if arrays equal, false otherwise.</returns>
  87. public static bool ConstantTimeAreEqual(byte[] a, byte[] b)
  88. {
  89. if (null == a || null == b)
  90. return false;
  91. if (a == b)
  92. return true;
  93. int len = System.Math.Min(a.Length, b.Length);
  94. int nonEqual = a.Length ^ b.Length;
  95. for (int i = 0; i < len; ++i)
  96. {
  97. nonEqual |= (a[i] ^ b[i]);
  98. }
  99. for (int i = len; i < b.Length; ++i)
  100. {
  101. nonEqual |= (b[i] ^ ~b[i]);
  102. }
  103. return 0 == nonEqual;
  104. }
  105. public static bool ConstantTimeAreEqual(BufferSegment a, BufferSegment b)
  106. {
  107. if (null == a || null == b)
  108. return false;
  109. if (a == b)
  110. return true;
  111. int len = System.Math.Min(a.Count, b.Count);
  112. int nonEqual = a.Count ^ b.Count;
  113. for (int i = 0; i < len; ++i)
  114. {
  115. nonEqual |= (a.Data[a.Offset + i] ^ b.Data[b.Offset + i]);
  116. }
  117. for (int i = len; i < b.Count; ++i)
  118. {
  119. nonEqual |= (b.Data[b.Offset + i] ^ ~b.Data[b.Offset + i]);
  120. }
  121. return 0 == nonEqual;
  122. }
  123. public static bool ConstantTimeAreEqual(int len, byte[] a, int aOff, byte[] b, int bOff)
  124. {
  125. if (null == a)
  126. throw new ArgumentNullException("a");
  127. if (null == b)
  128. throw new ArgumentNullException("b");
  129. if (len < 0)
  130. throw new ArgumentException("cannot be negative", "len");
  131. if (aOff > (a.Length - len))
  132. throw new IndexOutOfRangeException("'aOff' value invalid for specified length");
  133. if (bOff > (b.Length - len))
  134. throw new IndexOutOfRangeException("'bOff' value invalid for specified length");
  135. int d = 0;
  136. for (int i = 0; i < len; ++i)
  137. {
  138. d |= (a[aOff + i] ^ b[bOff + i]);
  139. }
  140. return 0 == d;
  141. }
  142. public static bool AreEqual(
  143. int[] a,
  144. int[] b)
  145. {
  146. if (a == b)
  147. return true;
  148. if (a == null || b == null)
  149. return false;
  150. return HaveSameContents(a, b);
  151. }
  152. public static bool AreEqual(uint[] a, uint[] b)
  153. {
  154. if (a == b)
  155. return true;
  156. if (a == null || b == null)
  157. return false;
  158. return HaveSameContents(a, b);
  159. }
  160. public static bool AreEqual(long[] a, long[] b)
  161. {
  162. if (a == b)
  163. return true;
  164. if (a == null || b == null)
  165. return false;
  166. return HaveSameContents(a, b);
  167. }
  168. public static bool AreEqual(ulong[] a, ulong[] b)
  169. {
  170. if (a == b)
  171. return true;
  172. if (a == null || b == null)
  173. return false;
  174. return HaveSameContents(a, b);
  175. }
  176. private static bool HaveSameContents(
  177. bool[] a,
  178. bool[] b)
  179. {
  180. int i = a.Length;
  181. if (i != b.Length)
  182. return false;
  183. while (i != 0)
  184. {
  185. --i;
  186. if (a[i] != b[i])
  187. return false;
  188. }
  189. return true;
  190. }
  191. private static bool HaveSameContents(
  192. char[] a,
  193. char[] b)
  194. {
  195. int i = a.Length;
  196. if (i != b.Length)
  197. return false;
  198. while (i != 0)
  199. {
  200. --i;
  201. if (a[i] != b[i])
  202. return false;
  203. }
  204. return true;
  205. }
  206. private static bool HaveSameContents(
  207. byte[] a,
  208. byte[] b)
  209. {
  210. int i = a.Length;
  211. if (i != b.Length)
  212. return false;
  213. while (i != 0)
  214. {
  215. --i;
  216. if (a[i] != b[i])
  217. return false;
  218. }
  219. return true;
  220. }
  221. private static bool HaveSameContents(
  222. int[] a,
  223. int[] b)
  224. {
  225. int i = a.Length;
  226. if (i != b.Length)
  227. return false;
  228. while (i != 0)
  229. {
  230. --i;
  231. if (a[i] != b[i])
  232. return false;
  233. }
  234. return true;
  235. }
  236. private static bool HaveSameContents(uint[] a, uint[] b)
  237. {
  238. int i = a.Length;
  239. if (i != b.Length)
  240. return false;
  241. while (i != 0)
  242. {
  243. --i;
  244. if (a[i] != b[i])
  245. return false;
  246. }
  247. return true;
  248. }
  249. private static bool HaveSameContents(long[] a, long[] b)
  250. {
  251. int i = a.Length;
  252. if (i != b.Length)
  253. return false;
  254. while (i != 0)
  255. {
  256. --i;
  257. if (a[i] != b[i])
  258. return false;
  259. }
  260. return true;
  261. }
  262. private static bool HaveSameContents(ulong[] a, ulong[] b)
  263. {
  264. int i = a.Length;
  265. if (i != b.Length)
  266. return false;
  267. while (i != 0)
  268. {
  269. --i;
  270. if (a[i] != b[i])
  271. return false;
  272. }
  273. return true;
  274. }
  275. public static string ToString(
  276. object[] a)
  277. {
  278. StringBuilder sb = new StringBuilder("[");
  279. if (a.Length > 0)
  280. {
  281. sb.Append(a[0]);
  282. for (int index = 1; index < a.Length; ++index)
  283. {
  284. sb.Append(", ").Append(a[index]);
  285. }
  286. }
  287. sb.Append(']');
  288. return sb.ToString();
  289. }
  290. public static int GetHashCode(byte[] data)
  291. {
  292. if (data == null)
  293. {
  294. return 0;
  295. }
  296. int i = data.Length;
  297. int hc = i + 1;
  298. while (--i >= 0)
  299. {
  300. hc *= 257;
  301. hc ^= data[i];
  302. }
  303. return hc;
  304. }
  305. public static int GetHashCode(byte[] data, int off, int len)
  306. {
  307. if (data == null)
  308. {
  309. return 0;
  310. }
  311. int i = len;
  312. int hc = i + 1;
  313. while (--i >= 0)
  314. {
  315. hc *= 257;
  316. hc ^= data[off + i];
  317. }
  318. return hc;
  319. }
  320. public static int GetHashCode(int[] data)
  321. {
  322. if (data == null)
  323. return 0;
  324. int i = data.Length;
  325. int hc = i + 1;
  326. while (--i >= 0)
  327. {
  328. hc *= 257;
  329. hc ^= data[i];
  330. }
  331. return hc;
  332. }
  333. public static int GetHashCode(ushort[] data)
  334. {
  335. if (data == null)
  336. return 0;
  337. int i = data.Length;
  338. int hc = i + 1;
  339. while (--i >= 0)
  340. {
  341. hc *= 257;
  342. hc ^= data[i];
  343. }
  344. return hc;
  345. }
  346. public static int GetHashCode(int[] data, int off, int len)
  347. {
  348. if (data == null)
  349. return 0;
  350. int i = len;
  351. int hc = i + 1;
  352. while (--i >= 0)
  353. {
  354. hc *= 257;
  355. hc ^= data[off + i];
  356. }
  357. return hc;
  358. }
  359. public static int GetHashCode(uint[] data)
  360. {
  361. if (data == null)
  362. return 0;
  363. int i = data.Length;
  364. int hc = i + 1;
  365. while (--i >= 0)
  366. {
  367. hc *= 257;
  368. hc ^= (int)data[i];
  369. }
  370. return hc;
  371. }
  372. public static int GetHashCode(uint[] data, int off, int len)
  373. {
  374. if (data == null)
  375. return 0;
  376. int i = len;
  377. int hc = i + 1;
  378. while (--i >= 0)
  379. {
  380. hc *= 257;
  381. hc ^= (int)data[off + i];
  382. }
  383. return hc;
  384. }
  385. public static int GetHashCode(ulong[] data)
  386. {
  387. if (data == null)
  388. return 0;
  389. int i = data.Length;
  390. int hc = i + 1;
  391. while (--i >= 0)
  392. {
  393. ulong di = data[i];
  394. hc *= 257;
  395. hc ^= (int)di;
  396. hc *= 257;
  397. hc ^= (int)(di >> 32);
  398. }
  399. return hc;
  400. }
  401. public static int GetHashCode(ulong[] data, int off, int len)
  402. {
  403. if (data == null)
  404. return 0;
  405. int i = len;
  406. int hc = i + 1;
  407. while (--i >= 0)
  408. {
  409. ulong di = data[off + i];
  410. hc *= 257;
  411. hc ^= (int)di;
  412. hc *= 257;
  413. hc ^= (int)(di >> 32);
  414. }
  415. return hc;
  416. }
  417. public static bool[] Clone(bool[] data)
  418. {
  419. return data == null ? null : (bool[])data.Clone();
  420. }
  421. public static byte[] Clone(byte[] data)
  422. {
  423. return data == null ? null : (byte[])data.Clone();
  424. }
  425. public static short[] Clone(short[] data)
  426. {
  427. return data == null ? null : (short[])data.Clone();
  428. }
  429. public static ushort[] Clone(ushort[] data)
  430. {
  431. return data == null ? null : (ushort[])data.Clone();
  432. }
  433. public static int[] Clone(int[] data)
  434. {
  435. return data == null ? null : (int[])data.Clone();
  436. }
  437. public static uint[] Clone(uint[] data)
  438. {
  439. return data == null ? null : (uint[])data.Clone();
  440. }
  441. public static long[] Clone(long[] data)
  442. {
  443. return data == null ? null : (long[])data.Clone();
  444. }
  445. public static ulong[] Clone(ulong[] data)
  446. {
  447. return data == null ? null : (ulong[])data.Clone();
  448. }
  449. public static byte[] Clone(byte[] data, byte[] existing)
  450. {
  451. if (data == null)
  452. return null;
  453. if (existing == null || existing.Length != data.Length)
  454. return Clone(data);
  455. Array.Copy(data, 0, existing, 0, existing.Length);
  456. return existing;
  457. }
  458. public static ulong[] Clone(ulong[] data, ulong[] existing)
  459. {
  460. if (data == null)
  461. return null;
  462. if (existing == null || existing.Length != data.Length)
  463. return Clone(data);
  464. Array.Copy(data, 0, existing, 0, existing.Length);
  465. return existing;
  466. }
  467. public static bool Contains(byte[] a, byte n)
  468. {
  469. for (int i = 0; i < a.Length; ++i)
  470. {
  471. if (a[i] == n)
  472. return true;
  473. }
  474. return false;
  475. }
  476. public static bool Contains(short[] a, short n)
  477. {
  478. for (int i = 0; i < a.Length; ++i)
  479. {
  480. if (a[i] == n)
  481. return true;
  482. }
  483. return false;
  484. }
  485. public static bool Contains(int[] a, int n)
  486. {
  487. for (int i = 0; i < a.Length; ++i)
  488. {
  489. if (a[i] == n)
  490. return true;
  491. }
  492. return false;
  493. }
  494. public static void Fill(
  495. byte[] buf,
  496. byte b)
  497. {
  498. int i = buf.Length;
  499. while (i > 0)
  500. {
  501. buf[--i] = b;
  502. }
  503. }
  504. public static void Fill(byte[] buf, int from, int to, byte b)
  505. {
  506. for (int i = from; i < to; ++i)
  507. {
  508. buf[i] = b;
  509. }
  510. }
  511. public static byte[] CopyOf(byte[] data, int newLength)
  512. {
  513. byte[] tmp = new byte[newLength];
  514. Array.Copy(data, 0, tmp, 0, System.Math.Min(newLength, data.Length));
  515. return tmp;
  516. }
  517. public static char[] CopyOf(char[] data, int newLength)
  518. {
  519. char[] tmp = new char[newLength];
  520. Array.Copy(data, 0, tmp, 0, System.Math.Min(newLength, data.Length));
  521. return tmp;
  522. }
  523. public static int[] CopyOf(int[] data, int newLength)
  524. {
  525. int[] tmp = new int[newLength];
  526. Array.Copy(data, 0, tmp, 0, System.Math.Min(newLength, data.Length));
  527. return tmp;
  528. }
  529. public static long[] CopyOf(long[] data, int newLength)
  530. {
  531. long[] tmp = new long[newLength];
  532. Array.Copy(data, 0, tmp, 0, System.Math.Min(newLength, data.Length));
  533. return tmp;
  534. }
  535. public static BigInteger[] CopyOf(BigInteger[] data, int newLength)
  536. {
  537. BigInteger[] tmp = new BigInteger[newLength];
  538. Array.Copy(data, 0, tmp, 0, System.Math.Min(newLength, data.Length));
  539. return tmp;
  540. }
  541. /**
  542. * Make a copy of a range of bytes from the passed in data array. The range can
  543. * extend beyond the end of the input array, in which case the return array will
  544. * be padded with zeroes.
  545. *
  546. * @param data the array from which the data is to be copied.
  547. * @param from the start index at which the copying should take place.
  548. * @param to the final index of the range (exclusive).
  549. *
  550. * @return a new byte array containing the range given.
  551. */
  552. public static byte[] CopyOfRange(byte[] data, int from, int to)
  553. {
  554. int newLength = GetLength(from, to);
  555. byte[] tmp = new byte[newLength];
  556. Array.Copy(data, from, tmp, 0, System.Math.Min(newLength, data.Length - from));
  557. return tmp;
  558. }
  559. public static int[] CopyOfRange(int[] data, int from, int to)
  560. {
  561. int newLength = GetLength(from, to);
  562. int[] tmp = new int[newLength];
  563. Array.Copy(data, from, tmp, 0, System.Math.Min(newLength, data.Length - from));
  564. return tmp;
  565. }
  566. public static long[] CopyOfRange(long[] data, int from, int to)
  567. {
  568. int newLength = GetLength(from, to);
  569. long[] tmp = new long[newLength];
  570. Array.Copy(data, from, tmp, 0, System.Math.Min(newLength, data.Length - from));
  571. return tmp;
  572. }
  573. public static BigInteger[] CopyOfRange(BigInteger[] data, int from, int to)
  574. {
  575. int newLength = GetLength(from, to);
  576. BigInteger[] tmp = new BigInteger[newLength];
  577. Array.Copy(data, from, tmp, 0, System.Math.Min(newLength, data.Length - from));
  578. return tmp;
  579. }
  580. private static int GetLength(int from, int to)
  581. {
  582. int newLength = to - from;
  583. if (newLength < 0)
  584. throw new ArgumentException(from + " > " + to);
  585. return newLength;
  586. }
  587. public static byte[] Append(byte[] a, byte b)
  588. {
  589. if (a == null)
  590. return new byte[] { b };
  591. int length = a.Length;
  592. byte[] result = new byte[length + 1];
  593. Array.Copy(a, 0, result, 0, length);
  594. result[length] = b;
  595. return result;
  596. }
  597. public static short[] Append(short[] a, short b)
  598. {
  599. if (a == null)
  600. return new short[] { b };
  601. int length = a.Length;
  602. short[] result = new short[length + 1];
  603. Array.Copy(a, 0, result, 0, length);
  604. result[length] = b;
  605. return result;
  606. }
  607. public static int[] Append(int[] a, int b)
  608. {
  609. if (a == null)
  610. return new int[] { b };
  611. int length = a.Length;
  612. int[] result = new int[length + 1];
  613. Array.Copy(a, 0, result, 0, length);
  614. result[length] = b;
  615. return result;
  616. }
  617. public static byte[] Concatenate(byte[] a, byte[] b)
  618. {
  619. if (a == null)
  620. return Clone(b);
  621. if (b == null)
  622. return Clone(a);
  623. byte[] rv = new byte[a.Length + b.Length];
  624. Array.Copy(a, 0, rv, 0, a.Length);
  625. Array.Copy(b, 0, rv, a.Length, b.Length);
  626. return rv;
  627. }
  628. public static ushort[] Concatenate(ushort[] a, ushort[] b)
  629. {
  630. if (a == null)
  631. return Clone(b);
  632. if (b == null)
  633. return Clone(a);
  634. ushort[] rv = new ushort[a.Length + b.Length];
  635. Array.Copy(a, 0, rv, 0, a.Length);
  636. Array.Copy(b, 0, rv, a.Length, b.Length);
  637. return rv;
  638. }
  639. public static byte[] ConcatenateAll(params byte[][] vs)
  640. {
  641. byte[][] nonNull = new byte[vs.Length][];
  642. int count = 0;
  643. int totalLength = 0;
  644. for (int i = 0; i < vs.Length; ++i)
  645. {
  646. byte[] v = vs[i];
  647. if (v != null)
  648. {
  649. nonNull[count++] = v;
  650. totalLength += v.Length;
  651. }
  652. }
  653. byte[] result = new byte[totalLength];
  654. int pos = 0;
  655. for (int j = 0; j < count; ++j)
  656. {
  657. byte[] v = nonNull[j];
  658. Array.Copy(v, 0, result, pos, v.Length);
  659. pos += v.Length;
  660. }
  661. return result;
  662. }
  663. public static int[] Concatenate(int[] a, int[] b)
  664. {
  665. if (a == null)
  666. return Clone(b);
  667. if (b == null)
  668. return Clone(a);
  669. int[] rv = new int[a.Length + b.Length];
  670. Array.Copy(a, 0, rv, 0, a.Length);
  671. Array.Copy(b, 0, rv, a.Length, b.Length);
  672. return rv;
  673. }
  674. public static byte[] Prepend(byte[] a, byte b)
  675. {
  676. if (a == null)
  677. return new byte[] { b };
  678. int length = a.Length;
  679. byte[] result = new byte[length + 1];
  680. Array.Copy(a, 0, result, 1, length);
  681. result[0] = b;
  682. return result;
  683. }
  684. public static short[] Prepend(short[] a, short b)
  685. {
  686. if (a == null)
  687. return new short[] { b };
  688. int length = a.Length;
  689. short[] result = new short[length + 1];
  690. Array.Copy(a, 0, result, 1, length);
  691. result[0] = b;
  692. return result;
  693. }
  694. public static int[] Prepend(int[] a, int b)
  695. {
  696. if (a == null)
  697. return new int[] { b };
  698. int length = a.Length;
  699. int[] result = new int[length + 1];
  700. Array.Copy(a, 0, result, 1, length);
  701. result[0] = b;
  702. return result;
  703. }
  704. public static byte[] Reverse(byte[] a)
  705. {
  706. if (a == null)
  707. return null;
  708. int p1 = 0, p2 = a.Length;
  709. byte[] result = new byte[p2];
  710. while (--p2 >= 0)
  711. {
  712. result[p2] = a[p1++];
  713. }
  714. return result;
  715. }
  716. public static int[] Reverse(int[] a)
  717. {
  718. if (a == null)
  719. return null;
  720. int p1 = 0, p2 = a.Length;
  721. int[] result = new int[p2];
  722. while (--p2 >= 0)
  723. {
  724. result[p2] = a[p1++];
  725. }
  726. return result;
  727. }
  728. public static byte[] ReverseInPlace(byte[] a)
  729. {
  730. if (null == a)
  731. return null;
  732. int p1 = 0, p2 = a.Length - 1;
  733. while (p1 < p2)
  734. {
  735. byte t1 = a[p1], t2 = a[p2];
  736. a[p1++] = t2;
  737. a[p2--] = t1;
  738. }
  739. return a;
  740. }
  741. public static int[] ReverseInPlace(int[] a)
  742. {
  743. if (null == a)
  744. return null;
  745. int p1 = 0, p2 = a.Length - 1;
  746. while (p1 < p2)
  747. {
  748. int t1 = a[p1], t2 = a[p2];
  749. a[p1++] = t2;
  750. a[p2--] = t1;
  751. }
  752. return a;
  753. }
  754. public static void Clear(byte[] data)
  755. {
  756. if (null != data)
  757. {
  758. Array.Clear(data, 0, data.Length);
  759. }
  760. }
  761. public static void Clear(int[] data)
  762. {
  763. if (null != data)
  764. {
  765. Array.Clear(data, 0, data.Length);
  766. }
  767. }
  768. public static bool IsNullOrContainsNull(object[] array)
  769. {
  770. if (null == array)
  771. return true;
  772. int count = array.Length;
  773. for (int i = 0; i < count; ++i)
  774. {
  775. if (null == array[i])
  776. return true;
  777. }
  778. return false;
  779. }
  780. public static bool IsNullOrEmpty(byte[] array)
  781. {
  782. return null == array || array.Length < 1;
  783. }
  784. public static bool IsNullOrEmpty(object[] array)
  785. {
  786. return null == array || array.Length < 1;
  787. }
  788. }
  789. }
  790. #pragma warning restore
  791. #endif