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 
11 #ifndef RTC_BASE_SSL_FINGERPRINT_H_
12 #define RTC_BASE_SSL_FINGERPRINT_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <string>
17 
18 #include "rtc_base/copy_on_write_buffer.h"
19 #include "rtc_base/system/rtc_export.h"
20 
21 namespace rtc {
22 
23 class RTCCertificate;
24 class SSLCertificate;
25 class SSLIdentity;
26 
27 struct RTC_EXPORT SSLFingerprint {
28   // TODO(steveanton): Remove once downstream projects have moved off of this.
29   static SSLFingerprint* Create(const std::string& algorithm,
30                                 const rtc::SSLIdentity* identity);
31   // TODO(steveanton): Rename to Create once projects have migrated.
32   static std::unique_ptr<SSLFingerprint> CreateUnique(
33       const std::string& algorithm,
34       const rtc::SSLIdentity& identity);
35 
36   static std::unique_ptr<SSLFingerprint> Create(
37       const std::string& algorithm,
38       const rtc::SSLCertificate& cert);
39 
40   // TODO(steveanton): Remove once downstream projects have moved off of this.
41   static SSLFingerprint* CreateFromRfc4572(const std::string& algorithm,
42                                            const std::string& fingerprint);
43   // TODO(steveanton): Rename to CreateFromRfc4572 once projects have migrated.
44   static std::unique_ptr<SSLFingerprint> CreateUniqueFromRfc4572(
45       const std::string& algorithm,
46       const std::string& fingerprint);
47 
48   // Creates a fingerprint from a certificate, using the same digest algorithm
49   // as the certificate's signature.
50   static std::unique_ptr<SSLFingerprint> CreateFromCertificate(
51       const RTCCertificate& cert);
52 
53   SSLFingerprint(const std::string& algorithm,
54                  ArrayView<const uint8_t> digest_view);
55   // TODO(steveanton): Remove once downstream projects have moved off of this.
56   SSLFingerprint(const std::string& algorithm,
57                  const uint8_t* digest_in,
58                  size_t digest_len);
59 
60   SSLFingerprint(const SSLFingerprint& from);
61 
62   bool operator==(const SSLFingerprint& other) const;
63 
64   std::string GetRfc4572Fingerprint() const;
65 
66   std::string ToString() const;
67 
68   std::string algorithm;
69   rtc::CopyOnWriteBuffer digest;
70 };
71 
72 }  // namespace rtc
73 
74 #endif  // RTC_BASE_SSL_FINGERPRINT_H_
75