Go to the documentation of this file.
26 #include <sys/types.h>
28 #if !defined(OPENSSL_WINDOWS)
31 #if !defined(O_BINARY)
39 #if !defined(PATH_MAX)
40 #define PATH_MAX MAX_PATH
75 fprintf(
stderr,
"Failed to open input file '%s': %s\n",
filename.c_str(),
80 #if !defined(OPENSSL_WINDOWS)
82 if (fstat(fd.
get(), &st)) {
83 fprintf(
stderr,
"Failed to stat input file '%s': %s\n",
filename.c_str(),
88 if (!S_ISREG(st.st_mode)) {
114 fd = scoped_fd.
get();
117 static const size_t kBufSize = 8192;
118 std::unique_ptr<uint8_t[]>
buf(
new uint8_t[kBufSize]);
120 bssl::ScopedEVP_MD_CTX
ctx;
122 fprintf(
stderr,
"Failed to initialize EVP_MD_CTX.\n");
129 fprintf(
stderr,
"Failed to read from %s: %s\n",
140 fprintf(
stderr,
"Failed to update hash.\n");
148 fprintf(
stderr,
"Failed to finish hash.\n");
153 static const char kHextable[] =
"0123456789abcdef";
154 for (
unsigned i = 0;
i < digest_len;
i++) {
156 hex_digest[
i * 2] = kHextable[
b >> 4];
157 hex_digest[
i * 2 + 1] = kHextable[
b & 0xf];
159 *out_hex =
std::string(hex_digest, digest_len * 2);
181 printf(
"%s %s\n", hex_digest.c_str(),
220 file = scoped_file.get();
226 unsigned bad_lines = 0;
227 unsigned parsed_lines = 0;
228 unsigned error_lines = 0;
229 unsigned bad_hash_lines = 0;
230 unsigned line_no = 0;
232 bool draining_overlong_line =
false;
241 fprintf(
stderr,
"Error reading from input.\n");
247 if (draining_overlong_line) {
249 draining_overlong_line =
false;
254 const bool overlong =
line[
len - 1] !=
'\n' && !feof(
file);
256 if (
len < hex_size + 2 + 1 ||
257 line[hex_size] !=
' ' ||
258 line[hex_size + 1] !=
' ' ||
262 fprintf(
stderr,
"%s: %u: improperly formatted line\n",
269 draining_overlong_line =
true;
286 if (target_filename ==
"-") {
290 target_source =
Source(target_filename);
293 if (!
SumFile(&calculated_hex_digest,
md, target_source)) {
302 printf(
"%s: FAILED\n", target_filename.c_str());
309 printf(
"%s: OK\n", target_filename.c_str());
314 if (bad_lines > 0 && parsed_lines > 0) {
315 fprintf(
stderr,
"WARNING: %u line%s improperly formatted\n", bad_lines,
316 bad_lines == 1 ?
" is" :
"s are");
318 if (error_lines > 0) {
319 fprintf(
stderr,
"WARNING: %u computed checksum(s) did NOT match\n",
324 if (parsed_lines == 0) {
325 fprintf(
stderr,
"%s: no properly formatted checksum lines found.\n",
336 const std::vector<std::string> &
args) {
337 bool check_mode =
false;
339 bool check_mode_args_given =
false;
343 while (
it !=
args.end()) {
345 if (!
arg.empty() &&
arg[0] !=
'-') {
361 if (
arg.size() >= 2 &&
arg[0] ==
'-' &&
arg[1] !=
'-') {
362 for (
size_t i = 1;
i <
arg.size();
i++) {
372 check_mode_args_given =
true;
373 check_args.
warn =
true;
376 fprintf(
stderr,
"Unknown option '%c'.\n",
arg[
i]);
380 }
else if (
arg ==
"--binary" ||
arg ==
"--text") {
382 }
else if (
arg ==
"--check") {
384 }
else if (
arg ==
"--quiet") {
385 check_mode_args_given =
true;
386 check_args.
quiet =
true;
387 }
else if (
arg ==
"--status") {
388 check_mode_args_given =
true;
390 }
else if (
arg ==
"--warn") {
391 check_mode_args_given =
true;
392 check_args.
warn =
true;
393 }
else if (
arg ==
"--strict") {
394 check_mode_args_given =
true;
397 fprintf(
stderr,
"Unknown option '%s'.\n",
arg.c_str());
402 if (check_mode_args_given && !check_mode) {
405 "Check mode arguments are only meaningful when verifying checksums.\n");
const OPENSSL_EXPORT EVP_MD * EVP_sha512(void)
const grpc_generator::File * file
const OPENSSL_EXPORT EVP_MD * EVP_sha384(void)
static const char kStdinName[]
bool MD5Sum(const std::vector< std::string > &args)
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Source(const std::string &name)
static struct test_ctx ctx
#define EVP_DigestInit_ex
const OPENSSL_EXPORT EVP_MD * EVP_sha256(void)
bool ReadFromFD(int fd, size_t *out_bytes_read, void *out, size_t num)
bool SHA512256Sum(const std::vector< std::string > &args)
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
static bool Check(const CheckModeArguments &args, const EVP_MD *md, const Source &source)
static bool DigestSum(const EVP_MD *md, const std::vector< std::string > &args)
const std::string & filename() const
ScopedFILE FDToFILE(ScopedFD fd, const char *mode)
OPENSSL_MSVC_PRAGMA(warning(disable:4702))
static ScopedFD OpenFile(const std::string &filename)
int push(void *desc, unsigned char *buf, unsigned len)
static bool PrintFileSum(const EVP_MD *md, const Source &source)
static bool SumFile(std::string *out_hex, const EVP_MD *md, const Source &source)
#define EVP_DigestFinal_ex
bool SHA224Sum(const std::vector< std::string > &args)
bool SHA512Sum(const std::vector< std::string > &args)
bool SHA384Sum(const std::vector< std::string > &args)
ScopedFD OpenFD(const char *path, int flags)
const OPENSSL_EXPORT EVP_MD * EVP_sha1(void)
bool SHA256Sum(const std::vector< std::string > &args)
const OPENSSL_EXPORT EVP_MD * EVP_md5(void)
bool SHA1Sum(const std::vector< std::string > &args)
const OPENSSL_EXPORT EVP_MD * EVP_sha512_256(void)
const OPENSSL_EXPORT EVP_MD * EVP_sha224(void)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:12