Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/numerics/safe_math.h" | 6 #include "base/numerics/safe_math.h" |
| 7 #include "net/der/input.h" | 7 #include "net/der/input.h" |
| 8 #include "net/der/parse_values.h" | 8 #include "net/der/parse_values.h" |
| 9 #include "net/der/parser.h" | 9 #include "net/der/parser.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 const uint8_t der[] = {0x02, 0x01, 0x01}; | 189 const uint8_t der[] = {0x02, 0x01, 0x01}; |
| 190 Parser parser((Input(der))); | 190 Parser parser((Input(der))); |
| 191 | 191 |
| 192 Input value; | 192 Input value; |
| 193 bool present; | 193 bool present; |
| 194 ASSERT_TRUE(parser.ReadOptionalTag(0x04, &value, &present)); | 194 ASSERT_TRUE(parser.ReadOptionalTag(0x04, &value, &present)); |
| 195 ASSERT_FALSE(present); | 195 ASSERT_FALSE(present); |
| 196 ASSERT_FALSE(parser.Advance()); | 196 ASSERT_FALSE(parser.Advance()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST(ParserTest, ReadBitString) { | |
| 200 const uint8_t der[] = {0x03, 0x03, 0x01, 0xAA, 0xBE}; | |
| 201 Parser parser((Input(der))); | |
|
davidben
2015/07/27 20:19:59
[I'm assuming the extra parens here are coming fro
eroman
2015/07/27 21:19:23
Correct.
I need those parenthesis to avoid a compi
| |
| 202 | |
| 203 Input bytes; | |
| 204 uint8_t unused_bits; | |
| 205 ASSERT_TRUE(parser.ReadBitString(&bytes, &unused_bits)); | |
| 206 EXPECT_FALSE(parser.HasMore()); | |
| 207 | |
| 208 EXPECT_EQ(1u, unused_bits); | |
| 209 ASSERT_EQ(2u, bytes.Length()); | |
| 210 EXPECT_EQ(0xAA, bytes.UnsafeData()[0]); | |
| 211 EXPECT_EQ(0xBE, bytes.UnsafeData()[1]); | |
| 212 } | |
| 213 | |
| 214 TEST(ParserTest, ReadBitString_BadTag) { | |
| 215 const uint8_t der[] = {0x05, 0x03, 0x01, 0xAA, 0xBE}; | |
| 216 Parser parser((Input(der))); | |
| 217 | |
| 218 Input bytes; | |
| 219 uint8_t unused_bits; | |
| 220 EXPECT_FALSE(parser.ReadBitString(&bytes, &unused_bits)); | |
| 221 } | |
| 222 | |
| 223 // Reads a BIT STRING with one unused bit -- should fail. | |
| 224 TEST(ParserTest, ReadBitStringNoUnusedBits) { | |
| 225 const uint8_t der[] = {0x03, 0x03, 0x01, 0xAA, 0xBE}; | |
| 226 Parser parser((Input(der))); | |
| 227 | |
| 228 Input bytes; | |
| 229 EXPECT_FALSE(parser.ReadBitStringNoUnusedBits(&bytes)); | |
|
davidben
2015/07/27 20:19:59
I dunno if you want a success test for NoUnusedBit
eroman
2015/07/27 21:19:23
Done.
I also improved the test descriptions.
| |
| 230 } | |
| 231 | |
| 199 } // namespace test | 232 } // namespace test |
| 200 } // namespace der | 233 } // namespace der |
| 201 } // namespace net | 234 } // namespace net |
| OLD | NEW |