2
0

HostKeyEventArgsBenchmarks.cs 1.7 KB

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