IsoTrailers.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using System.Collections;
  4. using Org.BouncyCastle.Crypto.Digests;
  5. using Org.BouncyCastle.Utilities;
  6. using Org.BouncyCastle.Utilities.Collections;
  7. namespace Org.BouncyCastle.Crypto.Signers
  8. {
  9. public class IsoTrailers
  10. {
  11. public const int TRAILER_IMPLICIT = 0xBC;
  12. public const int TRAILER_RIPEMD160 = 0x31CC;
  13. public const int TRAILER_RIPEMD128 = 0x32CC;
  14. public const int TRAILER_SHA1 = 0x33CC;
  15. public const int TRAILER_SHA256 = 0x34CC;
  16. public const int TRAILER_SHA512 = 0x35CC;
  17. public const int TRAILER_SHA384 = 0x36CC;
  18. public const int TRAILER_WHIRLPOOL = 0x37CC;
  19. public const int TRAILER_SHA224 = 0x38CC;
  20. public const int TRAILER_SHA512_224 = 0x39CC;
  21. public const int TRAILER_SHA512_256 = 0x40CC;
  22. private static IDictionary CreateTrailerMap()
  23. {
  24. IDictionary trailers = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  25. trailers.Add("RIPEMD128", TRAILER_RIPEMD128);
  26. trailers.Add("RIPEMD160", TRAILER_RIPEMD160);
  27. trailers.Add("SHA-1", TRAILER_SHA1);
  28. trailers.Add("SHA-224", TRAILER_SHA224);
  29. trailers.Add("SHA-256", TRAILER_SHA256);
  30. trailers.Add("SHA-384", TRAILER_SHA384);
  31. trailers.Add("SHA-512", TRAILER_SHA512);
  32. trailers.Add("SHA-512/224", TRAILER_SHA512_224);
  33. trailers.Add("SHA-512/256", TRAILER_SHA512_256);
  34. trailers.Add("Whirlpool", TRAILER_WHIRLPOOL);
  35. return CollectionUtilities.ReadOnly(trailers);
  36. }
  37. // IDictionary is (string -> Int32)
  38. private static readonly IDictionary trailerMap = CreateTrailerMap();
  39. public static int GetTrailer(IDigest digest)
  40. {
  41. return (int)trailerMap[digest.AlgorithmName];
  42. }
  43. public static bool NoTrailerAvailable(IDigest digest)
  44. {
  45. return !trailerMap.Contains(digest.AlgorithmName);
  46. }
  47. }
  48. }
  49. #endif