• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
20 
21 #include "perfetto/ext/base/string_view.h"
22 #include "test/gtest_and_gmock.h"
23 
24 namespace perfetto {
25 namespace base {
26 namespace {
27 
28 using testing::ElementsAreArray;
29 
TEST(SHA1Test,Hash)30 TEST(SHA1Test, Hash) {
31   EXPECT_THAT(SHA1Hash(""), ElementsAreArray<uint8_t>(
32                                 {0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b,
33                                  0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60,
34                                  0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09}));
35 
36   EXPECT_THAT(SHA1Hash("abc"), ElementsAreArray<uint8_t>(
37                                    {0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81,
38                                     0x6a, 0xba, 0x3e, 0x25, 0x71, 0x78, 0x50,
39                                     0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d}));
40 
41   EXPECT_THAT(
42       SHA1Hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
43       ElementsAreArray<uint8_t>({0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2,
44                                  0x6e, 0xba, 0xae, 0x4a, 0xa1, 0xf9, 0x51,
45                                  0x29, 0xe5, 0xe5, 0x46, 0x70, 0xf1}));
46 
47   EXPECT_THAT(
48       SHA1Hash(std::string(1000000, 'a')),
49       ElementsAreArray<uint8_t>({0x34, 0xaa, 0x97, 0x3c, 0xd4, 0xc4, 0xda,
50                                  0xa4, 0xf6, 0x1e, 0xeb, 0x2b, 0xdb, 0xad,
51                                  0x27, 0x31, 0x65, 0x34, 0x01, 0x6f}));
52 }
53 
54 }  // namespace
55 }  // namespace base
56 }  // namespace perfetto
57