Commit c415dfed authored by rsleevi's avatar rsleevi Committed by Commit bot

Add a template-specialized constructor for der::Input for constants

Make it easier to create der::Input's from constants by the magical
power of Templates.

Old and busted: der::Input foo(kFoo, arraysize(kFoo));
New hotness: der::Input foo(kFoo);

BUG=none
R=mattm@chromium.org

Review URL: https://codereview.chromium.org/1146283004

Cr-Commit-Position: refs/heads/master@{#330882}
parent 56de0e5c
...@@ -41,6 +41,11 @@ class NET_EXPORT_PRIVATE Input { ...@@ -41,6 +41,11 @@ class NET_EXPORT_PRIVATE Input {
// Creates an empty Input, one from which no data can be read. // Creates an empty Input, one from which no data can be read.
Input(); Input();
// Creates an Input from a constant array |data|.
template <size_t N>
explicit Input(const uint8_t(&data)[N])
: data_(data), len_(N) {}
// Creates an Input from the given |data| and |len|. // Creates an Input from the given |data| and |len|.
Input(const uint8_t* data, size_t len); Input(const uint8_t* data, size_t len);
......
...@@ -27,6 +27,14 @@ TEST(InputTest, Equals) { ...@@ -27,6 +27,14 @@ TEST(InputTest, Equals) {
EXPECT_FALSE(test_truncated.Equals(test)); EXPECT_FALSE(test_truncated.Equals(test));
} }
TEST(InputTest, StaticArray) {
Input input(kInput);
EXPECT_EQ(arraysize(kInput), input.Length());
Input input2(kInput, arraysize(kInput));
EXPECT_TRUE(input.Equals(input2));
}
TEST(ByteReaderTest, NoReadPastEnd) { TEST(ByteReaderTest, NoReadPastEnd) {
ByteReader reader(Input(nullptr, 0)); ByteReader reader(Input(nullptr, 0));
uint8_t data; uint8_t data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment