1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "perfetto/ext/base/http/sha1.h"
18
19 #include <cstdint>
20 #include <string>
21
22 #include "perfetto/ext/base/string_view.h"
23 #include "test/gtest_and_gmock.h"
24
25 namespace perfetto {
26 namespace base {
27 namespace {
28
29 using testing::ElementsAreArray;
30
TEST(SHA1Test,Hash)31 TEST(SHA1Test, Hash) {
32 EXPECT_THAT(SHA1Hash(""), ElementsAreArray<uint8_t>(
33 {0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b,
34 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60,
35 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09}));
36
37 EXPECT_THAT(SHA1Hash("abc"), ElementsAreArray<uint8_t>(
38 {0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81,
39 0x6a, 0xba, 0x3e, 0x25, 0x71, 0x78, 0x50,
40 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d}));
41
42 EXPECT_THAT(
43 SHA1Hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
44 ElementsAreArray<uint8_t>({0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2,
45 0x6e, 0xba, 0xae, 0x4a, 0xa1, 0xf9, 0x51,
46 0x29, 0xe5, 0xe5, 0x46, 0x70, 0xf1}));
47
48 EXPECT_THAT(
49 SHA1Hash(std::string(1000000, 'a')),
50 ElementsAreArray<uint8_t>({0x34, 0xaa, 0x97, 0x3c, 0xd4, 0xc4, 0xda,
51 0xa4, 0xf6, 0x1e, 0xeb, 0x2b, 0xdb, 0xad,
52 0x27, 0x31, 0x65, 0x34, 0x01, 0x6f}));
53 }
54
55 } // namespace
56 } // namespace base
57 } // namespace perfetto
58