Split hashing code into testing/utils/hash.h. Change-Id: Ia9b8a475c42cdedb26fec5abce093902c4eef6c7 Reviewed-on: https://pdfium-review.googlesource.com/c/49910 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fdrm/fx_crypt_unittest.cpp b/core/fdrm/fx_crypt_unittest.cpp index b6389d1..bf51988 100644 --- a/core/fdrm/fx_crypt_unittest.cpp +++ b/core/fdrm/fx_crypt_unittest.cpp
@@ -12,6 +12,7 @@ #include "core/fxcrt/fx_memory.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" +#include "testing/utils/hash.h" namespace {
diff --git a/fpdfsdk/fpdf_attachment_embeddertest.cpp b/fpdfsdk/fpdf_attachment_embeddertest.cpp index b128d82..6ab82f8 100644 --- a/fpdfsdk/fpdf_attachment_embeddertest.cpp +++ b/fpdfsdk/fpdf_attachment_embeddertest.cpp
@@ -9,6 +9,7 @@ #include "public/fpdf_attachment.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" +#include "testing/utils/hash.h" static constexpr char kDateKey[] = "CreationDate"; static constexpr char kChecksumKey[] = "CheckSum";
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index d911c54..895b9fe 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -26,6 +26,7 @@ #include "testing/gmock/include/gmock/gmock-matchers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" +#include "testing/utils/hash.h" class FPDFEditEmbedderTest : public EmbedderTest { protected:
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index 0751005..091d08a 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc
@@ -33,6 +33,7 @@ #include "samples/pdfium_test_event_helper.h" #include "samples/pdfium_test_write_helper.h" #include "testing/test_support.h" +#include "testing/utils/hash.h" #include "testing/utils/path_service.h" #include "third_party/base/logging.h" #include "third_party/base/optional.h"
diff --git a/testing/BUILD.gn b/testing/BUILD.gn index a80233c..f659121 100644 --- a/testing/BUILD.gn +++ b/testing/BUILD.gn
@@ -19,6 +19,8 @@ "test_support.h", "utils/bitmap_saver.cpp", "utils/bitmap_saver.h", + "utils/hash.cpp", + "utils/hash.h", "utils/path_service.cpp", "utils/path_service.h", ]
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index 2827458..bcdd41a 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp
@@ -21,6 +21,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/test_support.h" #include "testing/utils/bitmap_saver.h" +#include "testing/utils/hash.h" #include "testing/utils/path_service.h" #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h"
diff --git a/testing/test_support.cpp b/testing/test_support.cpp index cb0d37c..e9030a1 100644 --- a/testing/test_support.cpp +++ b/testing/test_support.cpp
@@ -7,7 +7,6 @@ #include <stdio.h> #include <string.h> -#include "core/fdrm/fx_crypt.h" #include "core/fxcrt/fx_string.h" std::unique_ptr<char, pdfium::FreeDeleter> GetFileContents(const char* filename, @@ -91,24 +90,6 @@ return result; } -std::string CryptToBase16(const uint8_t* digest) { - static char const zEncode[] = "0123456789abcdef"; - std::string ret; - ret.resize(32); - for (int i = 0, j = 0; i < 16; i++, j += 2) { - uint8_t a = digest[i]; - ret[j] = zEncode[(a >> 4) & 0xf]; - ret[j + 1] = zEncode[a & 0xf]; - } - return ret; -} - -std::string GenerateMD5Base16(const uint8_t* data, uint32_t size) { - uint8_t digest[16]; - CRYPT_MD5Generate(data, size, digest); - return CryptToBase16(digest); -} - TestLoader::TestLoader(const char* pBuf, size_t len) : m_pBuf(pBuf), m_Len(len) { }
diff --git a/testing/test_support.h b/testing/test_support.h index 6de36b1..ef70c62 100644 --- a/testing/test_support.h +++ b/testing/test_support.h
@@ -80,9 +80,6 @@ std::unique_ptr<unsigned short, pdfium::FreeDeleter> GetFPDFWideString( const std::wstring& wstr); -std::string CryptToBase16(const uint8_t* digest); -std::string GenerateMD5Base16(const uint8_t* data, uint32_t size); - class TestLoader { public: TestLoader(const char* pBuf, size_t len);
diff --git a/testing/utils/hash.cpp b/testing/utils/hash.cpp new file mode 100644 index 0000000..30dc562 --- /dev/null +++ b/testing/utils/hash.cpp
@@ -0,0 +1,25 @@ +// Copyright 2019 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "testing/utils/hash.h" + +#include "core/fdrm/fx_crypt.h" + +std::string CryptToBase16(const uint8_t* digest) { + static char const zEncode[] = "0123456789abcdef"; + std::string ret; + ret.resize(32); + for (int i = 0, j = 0; i < 16; i++, j += 2) { + uint8_t a = digest[i]; + ret[j] = zEncode[(a >> 4) & 0xf]; + ret[j + 1] = zEncode[a & 0xf]; + } + return ret; +} + +std::string GenerateMD5Base16(const uint8_t* data, uint32_t size) { + uint8_t digest[16]; + CRYPT_MD5Generate(data, size, digest); + return CryptToBase16(digest); +}
diff --git a/testing/utils/hash.h b/testing/utils/hash.h new file mode 100644 index 0000000..0e55165 --- /dev/null +++ b/testing/utils/hash.h
@@ -0,0 +1,13 @@ +// Copyright 2019 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef TESTING_UTILS_HASH_H_ +#define TESTING_UTILS_HASH_H_ + +#include <string> + +std::string CryptToBase16(const uint8_t* digest); +std::string GenerateMD5Base16(const uint8_t* data, uint32_t size); + +#endif // TESTING_UTILS_HASH_H_
diff --git a/xfa/fwl/cfx_barcode_unittest.cpp b/xfa/fwl/cfx_barcode_unittest.cpp index 0afc521..36c47f8 100644 --- a/xfa/fwl/cfx_barcode_unittest.cpp +++ b/xfa/fwl/cfx_barcode_unittest.cpp
@@ -16,6 +16,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" #include "testing/utils/bitmap_saver.h" +#include "testing/utils/hash.h" #include "third_party/base/ptr_util.h" class BarcodeTest : public testing::Test {