blob: 9e37c5fe3762851066819a1203c9d26a640e261b [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
23#include "mincrypt/sha.h"
24
25static std::string print_sha1(const uint8_t sha1[SHA_DIGEST_SIZE], 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
35static std::string print_sha1(const uint8_t sha1[SHA_DIGEST_SIZE]) {
36 return print_sha1(sha1, SHA_DIGEST_SIZE);
37}
38
39static std::string short_sha1(const uint8_t sha1[SHA_DIGEST_SIZE]) {
40 return print_sha1(sha1, 4);
41}
42
43#endif // RECOVERY_PRINT_SHA1_H