blob: b204bc77f300211c73f4c47c216f38b3b91eeed9 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_SSLFINGERPRINT_H_
12#define RTC_BASE_SSLFINGERPRINT_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014#include <string>
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000015
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/copyonwritebuffer.h"
17#include "rtc_base/rtccertificate.h"
18#include "rtc_base/sslidentity.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020019
20namespace rtc {
21
22class SSLCertificate;
23
24struct SSLFingerprint {
Henrik Grunell2b156262018-10-11 11:15:48 +000025 static SSLFingerprint* Create(const std::string& algorithm,
Mirko Bonadei6932fb22018-10-15 14:18:03 +000026 const rtc::SSLIdentity* identity);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020027
Mirko Bonadei6932fb22018-10-15 14:18:03 +000028 static SSLFingerprint* Create(const std::string& algorithm,
29 const rtc::SSLCertificate* cert);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020030
31 static SSLFingerprint* CreateFromRfc4572(const std::string& algorithm,
32 const std::string& fingerprint);
33
34 // Creates a fingerprint from a certificate, using the same digest algorithm
35 // as the certificate's signature.
Mirko Bonadei6932fb22018-10-15 14:18:03 +000036 static SSLFingerprint* CreateFromCertificate(const RTCCertificate* cert);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020037
38 SSLFingerprint(const std::string& algorithm,
39 const uint8_t* digest_in,
40 size_t digest_len);
41
42 SSLFingerprint(const SSLFingerprint& from);
43
44 bool operator==(const SSLFingerprint& other) const;
45
46 std::string GetRfc4572Fingerprint() const;
47
48 std::string ToString() const;
49
50 std::string algorithm;
51 rtc::CopyOnWriteBuffer digest;
52};
53
54} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000055
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020056#endif // RTC_BASE_SSLFINGERPRINT_H_