2015-08-06 00:20:27 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RECOVERY_PRINT_SHA1_H
|
|
|
|
#define RECOVERY_PRINT_SHA1_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
|
|
|
|
2016-11-03 19:37:15 +01:00
|
|
|
#include <openssl/sha.h>
|
2015-08-06 00:20:27 +02:00
|
|
|
|
2016-04-20 07:31:01 +02:00
|
|
|
static std::string print_sha1(const uint8_t* sha1, size_t len) {
|
2015-08-06 00:20:27 +02:00
|
|
|
const char* hex = "0123456789abcdef";
|
|
|
|
std::string result = "";
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
result.push_back(hex[(sha1[i]>>4) & 0xf]);
|
|
|
|
result.push_back(hex[sha1[i] & 0xf]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:15:07 +02:00
|
|
|
[[maybe_unused]] static std::string print_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH]) {
|
2016-02-04 09:23:21 +01:00
|
|
|
return print_sha1(sha1, SHA_DIGEST_LENGTH);
|
2015-08-06 00:20:27 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 23:15:07 +02:00
|
|
|
[[maybe_unused]] static std::string short_sha1(const uint8_t sha1[SHA_DIGEST_LENGTH]) {
|
2015-08-06 00:20:27 +02:00
|
|
|
return print_sha1(sha1, 4);
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:15:07 +02:00
|
|
|
[[maybe_unused]] static std::string print_hex(const uint8_t* bytes, size_t len) {
|
2016-11-03 19:37:15 +01:00
|
|
|
return print_sha1(bytes, len);
|
2016-04-20 07:31:01 +02:00
|
|
|
}
|
|
|
|
|
2015-08-06 00:20:27 +02:00
|
|
|
#endif // RECOVERY_PRINT_SHA1_H
|