blob: fa3d7e009f872282bc123c4f1f1d0038eb62bc8c [file] [log] [blame]
Tao Baoe6aa3322015-08-05 15:20:27 -07001/*
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
Sen Jiangc48cb5e2016-02-04 16:23:21 +080023#include "openssl/sha.h"
Tao Baoe6aa3322015-08-05 15:20:27 -070024
Sen Jiangc48cb5e2016-02-04 16:23:21 +080025static std::string print_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH], size_t len) {
Tao Baoe6aa3322015-08-05 15:20:27 -070026 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
Sen Jiangc48cb5e2016-02-04 16:23:21 +080035static std::string print_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH]) {
36 return print_sha1(sha1, SHA_DIGEST_LENGTH);
Tao Baoe6aa3322015-08-05 15:20:27 -070037}
38
Sen Jiangc48cb5e2016-02-04 16:23:21 +080039static std::string short_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH]) {
Tao Baoe6aa3322015-08-05 15:20:27 -070040 return print_sha1(sha1, 4);
41}
42
43#endif // RECOVERY_PRINT_SHA1_H