HostKeyEventArgsBenchmarks.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using BenchmarkDotNet.Attributes;
  2. using Renci.SshNet.Benchmarks.Security.Cryptography.Ciphers;
  3. using Renci.SshNet.Common;
  4. using Renci.SshNet.Security;
  5. namespace Renci.SshNet.Benchmarks.Common
  6. {
  7. [MemoryDiagnoser]
  8. [ShortRunJob]
  9. public class HostKeyEventArgsBenchmarks
  10. {
  11. private readonly KeyHostAlgorithm _keyHostAlgorithm;
  12. public HostKeyEventArgsBenchmarks()
  13. {
  14. _keyHostAlgorithm = GetKeyHostAlgorithm();
  15. }
  16. private static KeyHostAlgorithm GetKeyHostAlgorithm()
  17. {
  18. using (var s = typeof(RsaCipherBenchmarks).Assembly.GetManifestResourceStream("Renci.SshNet.Benchmarks.Data.Key.RSA.txt"))
  19. {
  20. var privateKey = new PrivateKeyFile(s);
  21. return (KeyHostAlgorithm) privateKey.HostKeyAlgorithms.First();
  22. }
  23. }
  24. [Benchmark()]
  25. public HostKeyEventArgs Constructor()
  26. {
  27. return new HostKeyEventArgs(_keyHostAlgorithm);
  28. }
  29. [Benchmark()]
  30. public (string, string) CalculateFingerPrintSHA256AndMD5()
  31. {
  32. var test = new HostKeyEventArgs(_keyHostAlgorithm);
  33. return (test.FingerPrintSHA256, test.FingerPrintMD5);
  34. }
  35. [Benchmark()]
  36. public string CalculateFingerPrintSHA256()
  37. {
  38. var test = new HostKeyEventArgs(_keyHostAlgorithm);
  39. return test.FingerPrintSHA256;
  40. }
  41. [Benchmark()]
  42. public byte[] CalculateFingerPrint()
  43. {
  44. var test = new HostKeyEventArgs(_keyHostAlgorithm);
  45. return test.FingerPrint;
  46. }
  47. [Benchmark()]
  48. public string CalculateFingerPrintMD5()
  49. {
  50. var test = new HostKeyEventArgs(_keyHostAlgorithm);
  51. return test.FingerPrintSHA256;
  52. }
  53. }
  54. }