1 | //===-- Checksum.cpp ------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "lldb/Utility/Checksum.h" |
10 | #include "llvm/ADT/STLExtras.h" |
11 | #include "llvm/ADT/SmallString.h" |
12 | |
13 | using namespace lldb_private; |
14 | |
15 | Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); } |
16 | |
17 | Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); } |
18 | |
19 | Checksum &Checksum::operator=(const Checksum &checksum) { |
20 | SetMD5(checksum.m_checksum); |
21 | return *this; |
22 | } |
23 | |
24 | void Checksum::SetMD5(llvm::MD5::MD5Result md5) { |
25 | const constexpr size_t md5_length = 16; |
26 | std::uninitialized_copy_n(first: md5.begin(), n: md5_length, result: m_checksum.begin()); |
27 | } |
28 | |
29 | Checksum::operator bool() const { return !llvm::equal(LRange: m_checksum, RRange&: g_sentinel); } |
30 | |
31 | bool Checksum::operator==(const Checksum &checksum) const { |
32 | return llvm::equal(LRange: m_checksum, RRange: checksum.m_checksum); |
33 | } |
34 | |
35 | bool Checksum::operator!=(const Checksum &checksum) const { |
36 | return !(*this == checksum); |
37 | } |
38 | |
39 | std::string Checksum::digest() const { |
40 | return std::string(m_checksum.digest()); |
41 | } |
42 | |
43 | llvm::MD5::MD5Result Checksum::g_sentinel = { |
44 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; |
45 | |