ssl_fingerprint.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2012 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef RTC_BASE_SSL_FINGERPRINT_H_
  11. #define RTC_BASE_SSL_FINGERPRINT_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <string>
  15. #include "rtc_base/copy_on_write_buffer.h"
  16. #include "rtc_base/system/rtc_export.h"
  17. namespace rtc {
  18. class RTCCertificate;
  19. class SSLCertificate;
  20. class SSLIdentity;
  21. struct RTC_EXPORT SSLFingerprint {
  22. // TODO(steveanton): Remove once downstream projects have moved off of this.
  23. static SSLFingerprint* Create(const std::string& algorithm,
  24. const rtc::SSLIdentity* identity);
  25. // TODO(steveanton): Rename to Create once projects have migrated.
  26. static std::unique_ptr<SSLFingerprint> CreateUnique(
  27. const std::string& algorithm,
  28. const rtc::SSLIdentity& identity);
  29. static std::unique_ptr<SSLFingerprint> Create(
  30. const std::string& algorithm,
  31. const rtc::SSLCertificate& cert);
  32. // TODO(steveanton): Remove once downstream projects have moved off of this.
  33. static SSLFingerprint* CreateFromRfc4572(const std::string& algorithm,
  34. const std::string& fingerprint);
  35. // TODO(steveanton): Rename to CreateFromRfc4572 once projects have migrated.
  36. static std::unique_ptr<SSLFingerprint> CreateUniqueFromRfc4572(
  37. const std::string& algorithm,
  38. const std::string& fingerprint);
  39. // Creates a fingerprint from a certificate, using the same digest algorithm
  40. // as the certificate's signature.
  41. static std::unique_ptr<SSLFingerprint> CreateFromCertificate(
  42. const RTCCertificate& cert);
  43. SSLFingerprint(const std::string& algorithm,
  44. ArrayView<const uint8_t> digest_view);
  45. // TODO(steveanton): Remove once downstream projects have moved off of this.
  46. SSLFingerprint(const std::string& algorithm,
  47. const uint8_t* digest_in,
  48. size_t digest_len);
  49. SSLFingerprint(const SSLFingerprint& from);
  50. bool operator==(const SSLFingerprint& other) const;
  51. std::string GetRfc4572Fingerprint() const;
  52. std::string ToString() const;
  53. std::string algorithm;
  54. rtc::CopyOnWriteBuffer digest;
  55. };
  56. } // namespace rtc
  57. #endif // RTC_BASE_SSL_FINGERPRINT_H_