Remove special MD5 / SHA-1 digest classes.
Previous users have switched to the generic MessageDigest class in https://webrtc-review.googlesource.com/35040 Bug: webrtc:8677 Change-Id: Id58d5a02e04f53d256a41a98ead37e1844479a17 Reviewed-on: https://webrtc-review.googlesource.com/55061 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Joachim Bauch <jbauch@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22101}
This commit is contained in:
parent
0dd1b0a4b2
commit
6bd3cddcef
@ -841,8 +841,6 @@ rtc_source_set("rtc_base_tests_utils") {
|
||||
"httpbase.h",
|
||||
"httpserver.cc",
|
||||
"httpserver.h",
|
||||
"md5digest.cc",
|
||||
"md5digest.h",
|
||||
"memory_usage.cc",
|
||||
"memory_usage.h",
|
||||
"natserver.cc",
|
||||
@ -854,8 +852,6 @@ rtc_source_set("rtc_base_tests_utils") {
|
||||
"proxyserver.cc",
|
||||
"proxyserver.h",
|
||||
"refcount.h",
|
||||
"sha1digest.cc",
|
||||
"sha1digest.h",
|
||||
"sigslottester.h",
|
||||
"sigslottester.h.pump",
|
||||
"testbase64.h",
|
||||
@ -882,14 +878,6 @@ rtc_source_set("rtc_base_tests_utils") {
|
||||
public_deps = [
|
||||
"//testing/gtest",
|
||||
]
|
||||
|
||||
# TODO(jbauch): Remove once "md5digest" and "sha1digest" files have been
|
||||
# removed.
|
||||
if (rtc_build_ssl) {
|
||||
deps += [ "//third_party/boringssl" ]
|
||||
} else {
|
||||
configs += [ ":external_ssl_library" ]
|
||||
}
|
||||
}
|
||||
|
||||
rtc_source_set("rtc_task_queue_for_test") {
|
||||
@ -975,7 +963,6 @@ if (rtc_include_tests) {
|
||||
"file_unittest.cc",
|
||||
"function_view_unittest.cc",
|
||||
"logging_unittest.cc",
|
||||
"md5digest_unittest.cc",
|
||||
"numerics/histogram_percentile_counter_unittest.cc",
|
||||
"numerics/mod_ops_unittest.cc",
|
||||
"numerics/moving_max_counter_unittest.cc",
|
||||
@ -1014,14 +1001,6 @@ if (rtc_include_tests) {
|
||||
"../system_wrappers:system_wrappers",
|
||||
"../test:test_support",
|
||||
]
|
||||
|
||||
# TODO(jbauch): Remove once "md5digest" and "sha1digest" files have been
|
||||
# removed.
|
||||
if (rtc_build_ssl) {
|
||||
deps += [ "//third_party/boringssl" ]
|
||||
} else {
|
||||
configs += [ ":external_ssl_library" ]
|
||||
}
|
||||
}
|
||||
|
||||
rtc_source_set("rtc_task_queue_unittests") {
|
||||
@ -1118,7 +1097,6 @@ if (rtc_include_tests) {
|
||||
"rollingaccumulator_unittest.cc",
|
||||
"rtccertificate_unittest.cc",
|
||||
"rtccertificategenerator_unittest.cc",
|
||||
"sha1digest_unittest.cc",
|
||||
"signalthread_unittest.cc",
|
||||
"sigslot_unittest.cc",
|
||||
"sigslottester_unittest.cc",
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "rtc_base/md5digest.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
size_t Md5Digest::Size() const {
|
||||
return kSize;
|
||||
}
|
||||
|
||||
void Md5Digest::Update(const void* buf, size_t len) {
|
||||
MD5_Update(&ctx_, static_cast<const uint8_t*>(buf), len);
|
||||
}
|
||||
|
||||
size_t Md5Digest::Finish(void* buf, size_t len) {
|
||||
if (len < kSize) {
|
||||
return 0;
|
||||
}
|
||||
MD5_Final(static_cast<uint8_t*>(buf), &ctx_);
|
||||
MD5_Init(&ctx_); // Reset for next use.
|
||||
return kSize;
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef RTC_BASE_MD5DIGEST_H_
|
||||
#define RTC_BASE_MD5DIGEST_H_
|
||||
|
||||
#include <openssl/md5.h>
|
||||
|
||||
#include "rtc_base/messagedigest.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
// A simple wrapper for the MD5 implementation.
|
||||
class Md5Digest : public MessageDigest {
|
||||
public:
|
||||
enum { kSize = MD5_DIGEST_LENGTH };
|
||||
Md5Digest() {
|
||||
MD5_Init(&ctx_);
|
||||
}
|
||||
size_t Size() const override;
|
||||
void Update(const void* buf, size_t len) override;
|
||||
size_t Finish(void* buf, size_t len) override;
|
||||
|
||||
private:
|
||||
MD5_CTX ctx_;
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_MD5DIGEST_H_
|
||||
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "rtc_base/md5digest.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/stringencode.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
std::string Md5(const std::string& input) {
|
||||
Md5Digest md5;
|
||||
return ComputeDigest(&md5, input);
|
||||
}
|
||||
|
||||
TEST(Md5DigestTest, TestSize) {
|
||||
Md5Digest md5;
|
||||
EXPECT_EQ(16, static_cast<int>(Md5Digest::kSize));
|
||||
EXPECT_EQ(16U, md5.Size());
|
||||
}
|
||||
|
||||
TEST(Md5DigestTest, TestBasic) {
|
||||
// These are the standard MD5 test vectors from RFC 1321.
|
||||
EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", Md5(""));
|
||||
EXPECT_EQ("0cc175b9c0f1b6a831c399e269772661", Md5("a"));
|
||||
EXPECT_EQ("900150983cd24fb0d6963f7d28e17f72", Md5("abc"));
|
||||
EXPECT_EQ("f96b697d7cb7938d525a2f31aaf161d0", Md5("message digest"));
|
||||
EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b",
|
||||
Md5("abcdefghijklmnopqrstuvwxyz"));
|
||||
}
|
||||
|
||||
TEST(Md5DigestTest, TestMultipleUpdates) {
|
||||
Md5Digest md5;
|
||||
std::string input = "abcdefghijklmnopqrstuvwxyz";
|
||||
char output[Md5Digest::kSize];
|
||||
for (size_t i = 0; i < input.size(); ++i) {
|
||||
md5.Update(&input[i], 1);
|
||||
}
|
||||
EXPECT_EQ(md5.Size(), md5.Finish(output, sizeof(output)));
|
||||
EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b",
|
||||
hex_encode(output, sizeof(output)));
|
||||
}
|
||||
|
||||
TEST(Md5DigestTest, TestReuse) {
|
||||
Md5Digest md5;
|
||||
std::string input = "message digest";
|
||||
EXPECT_EQ("f96b697d7cb7938d525a2f31aaf161d0", ComputeDigest(&md5, input));
|
||||
input = "abcdefghijklmnopqrstuvwxyz";
|
||||
EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b", ComputeDigest(&md5, input));
|
||||
}
|
||||
|
||||
TEST(Md5DigestTest, TestBufferTooSmall) {
|
||||
Md5Digest md5;
|
||||
std::string input = "abcdefghijklmnopqrstuvwxyz";
|
||||
char output[Md5Digest::kSize - 1];
|
||||
md5.Update(input.c_str(), input.size());
|
||||
EXPECT_EQ(0U, md5.Finish(output, sizeof(output)));
|
||||
}
|
||||
|
||||
TEST(Md5DigestTest, TestBufferConst) {
|
||||
Md5Digest md5;
|
||||
const int kLongSize = 1000000;
|
||||
std::string input(kLongSize, '\0');
|
||||
for (int i = 0; i < kLongSize; ++i) {
|
||||
input[i] = static_cast<char>(i);
|
||||
}
|
||||
md5.Update(input.c_str(), input.size());
|
||||
for (int i = 0; i < kLongSize; ++i) {
|
||||
EXPECT_EQ(static_cast<char>(i), input[i]);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "rtc_base/sha1digest.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
size_t Sha1Digest::Size() const {
|
||||
return kSize;
|
||||
}
|
||||
|
||||
void Sha1Digest::Update(const void* buf, size_t len) {
|
||||
SHA1_Update(&ctx_, static_cast<const uint8_t*>(buf), len);
|
||||
}
|
||||
|
||||
size_t Sha1Digest::Finish(void* buf, size_t len) {
|
||||
if (len < kSize) {
|
||||
return 0;
|
||||
}
|
||||
SHA1_Final(static_cast<uint8_t*>(buf), &ctx_);
|
||||
SHA1_Init(&ctx_); // Reset for next use.
|
||||
return kSize;
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef RTC_BASE_SHA1DIGEST_H_
|
||||
#define RTC_BASE_SHA1DIGEST_H_
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "rtc_base/messagedigest.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
// A simple wrapper for the SHA-1 implementation.
|
||||
class Sha1Digest : public MessageDigest {
|
||||
public:
|
||||
enum { kSize = SHA_DIGEST_LENGTH };
|
||||
Sha1Digest() {
|
||||
SHA1_Init(&ctx_);
|
||||
}
|
||||
size_t Size() const override;
|
||||
void Update(const void* buf, size_t len) override;
|
||||
size_t Finish(void* buf, size_t len) override;
|
||||
|
||||
private:
|
||||
SHA_CTX ctx_;
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_SHA1DIGEST_H_
|
||||
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "rtc_base/sha1digest.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/stringencode.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
std::string Sha1(const std::string& input) {
|
||||
Sha1Digest sha1;
|
||||
return ComputeDigest(&sha1, input);
|
||||
}
|
||||
|
||||
TEST(Sha1DigestTest, TestSize) {
|
||||
Sha1Digest sha1;
|
||||
EXPECT_EQ(20, static_cast<int>(Sha1Digest::kSize));
|
||||
EXPECT_EQ(20U, sha1.Size());
|
||||
}
|
||||
|
||||
TEST(Sha1DigestTest, TestBasic) {
|
||||
// Test vectors from sha1.c.
|
||||
EXPECT_EQ("da39a3ee5e6b4b0d3255bfef95601890afd80709", Sha1(""));
|
||||
EXPECT_EQ("a9993e364706816aba3e25717850c26c9cd0d89d", Sha1("abc"));
|
||||
EXPECT_EQ("84983e441c3bd26ebaae4aa1f95129e5e54670f1",
|
||||
Sha1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"));
|
||||
std::string a_million_as(1000000, 'a');
|
||||
EXPECT_EQ("34aa973cd4c4daa4f61eeb2bdbad27316534016f", Sha1(a_million_as));
|
||||
}
|
||||
|
||||
TEST(Sha1DigestTest, TestMultipleUpdates) {
|
||||
Sha1Digest sha1;
|
||||
std::string input =
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
char output[Sha1Digest::kSize];
|
||||
for (size_t i = 0; i < input.size(); ++i) {
|
||||
sha1.Update(&input[i], 1);
|
||||
}
|
||||
EXPECT_EQ(sha1.Size(), sha1.Finish(output, sizeof(output)));
|
||||
EXPECT_EQ("84983e441c3bd26ebaae4aa1f95129e5e54670f1",
|
||||
hex_encode(output, sizeof(output)));
|
||||
}
|
||||
|
||||
TEST(Sha1DigestTest, TestReuse) {
|
||||
Sha1Digest sha1;
|
||||
std::string input = "abc";
|
||||
EXPECT_EQ("a9993e364706816aba3e25717850c26c9cd0d89d",
|
||||
ComputeDigest(&sha1, input));
|
||||
input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
EXPECT_EQ("84983e441c3bd26ebaae4aa1f95129e5e54670f1",
|
||||
ComputeDigest(&sha1, input));
|
||||
}
|
||||
|
||||
TEST(Sha1DigestTest, TestBufferTooSmall) {
|
||||
Sha1Digest sha1;
|
||||
std::string input = "abcdefghijklmnopqrstuvwxyz";
|
||||
char output[Sha1Digest::kSize - 1];
|
||||
sha1.Update(input.c_str(), input.size());
|
||||
EXPECT_EQ(0U, sha1.Finish(output, sizeof(output)));
|
||||
}
|
||||
|
||||
TEST(Sha1DigestTest, TestBufferConst) {
|
||||
Sha1Digest sha1;
|
||||
const int kLongSize = 1000000;
|
||||
std::string input(kLongSize, '\0');
|
||||
for (int i = 0; i < kLongSize; ++i) {
|
||||
input[i] = static_cast<char>(i);
|
||||
}
|
||||
sha1.Update(input.c_str(), input.size());
|
||||
for (int i = 0; i < kLongSize; ++i) {
|
||||
EXPECT_EQ(static_cast<char>(i), input[i]);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
Loading…
x
Reference in New Issue
Block a user