Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: net/der/parser_unittest.cc

Issue 1248043002: Add functions for DER parsing a BIT STRING. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/der/parser.cc ('K') | « net/der/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/der/parser_unittest.cc
diff --git a/net/der/parser_unittest.cc b/net/der/parser_unittest.cc
index 1943d6b86ebeb8fa79e1aa5df8147152e30d1681..10dac493978bde5deb86b344ec63e9818c5bcb51 100644
--- a/net/der/parser_unittest.cc
+++ b/net/der/parser_unittest.cc
@@ -196,6 +196,39 @@ TEST(ParserTest, CannotAdvanceAfterReadOptionalTag) {
ASSERT_FALSE(parser.Advance());
}
+TEST(ParserTest, ReadBitString) {
+ const uint8_t der[] = {0x03, 0x03, 0x01, 0xAA, 0xBE};
+ Parser parser((Input(der)));
+
+ Input bytes;
+ uint8_t unused_bits;
+ ASSERT_TRUE(parser.ReadBitString(&bytes, &unused_bits));
+ ASSERT_FALSE(parser.HasMore());
nharper 2015/07/21 23:23:47 EXPECT_FALSE
eroman 2015/07/22 17:05:23 Done.
+
+ ASSERT_EQ(2u, bytes.Length());
+ ASSERT_EQ(1u, unused_bits);
+ ASSERT_EQ(0xAA, bytes.UnsafeData()[0]);
+ ASSERT_EQ(0xBE, bytes.UnsafeData()[1]);
nharper 2015/07/21 23:23:47 EXPECT_EQ (for lines 209-211) Only parser.ReadBitS
eroman 2015/07/22 17:05:23 Done.
+}
+
+TEST(ParserTest, ReadBitString_BadTag) {
+ const uint8_t der[] = {0x05, 0x03, 0x01, 0xAA, 0xBE};
+ Parser parser((Input(der)));
+
+ Input bytes;
+ uint8_t unused_bits;
+ ASSERT_FALSE(parser.ReadBitString(&bytes, &unused_bits));
+}
+
+// Reads a BIT STRING with one unused bit -- should fail.
+TEST(ParserTest, ReadBitStringNoUnusedBits) {
+ const uint8_t der[] = {0x03, 0x03, 0x01, 0xAA, 0xBE};
+ Parser parser((Input(der)));
+
+ Input bytes;
+ ASSERT_FALSE(parser.ReadBitStringNoUnusedBits(&bytes));
+}
+
} // namespace test
} // namespace der
} // namespace net
« net/der/parser.cc ('K') | « net/der/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698