1 /*
2 * Copyright (C) 2015 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 #ifndef RECOVERY_PRINT_SHA1_H
18 #define RECOVERY_PRINT_SHA1_H
19
20 #include <stdint.h>
21 #include <string>
22
23 #include <openssl/sha.h>
24
print_sha1(const uint8_t * sha1,size_t len)25 static std::string print_sha1(const uint8_t* sha1, size_t len) {
26 const char* hex = "0123456789abcdef";
27 std::string result = "";
28 for (size_t i = 0; i < len; ++i) {
29 result.push_back(hex[(sha1[i] >> 4) & 0xf]);
30 result.push_back(hex[sha1[i] & 0xf]);
31 }
32 return result;
33 }
34
print_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH])35 [[maybe_unused]] static std::string print_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH]) {
36 return print_sha1(sha1, SHA_DIGEST_LENGTH);
37 }
38
short_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH])39 [[maybe_unused]] static std::string short_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH]) {
40 return print_sha1(sha1, 4);
41 }
42
print_hex(const uint8_t * bytes,size_t len)43 [[maybe_unused]] static std::string print_hex(const uint8_t* bytes, size_t len) {
44 return print_sha1(bytes, len);
45 }
46
47 #endif // RECOVERY_PRINT_SHA1_H
48