| 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 "components/gcm_driver/crypto/encryption_header_parsers.h" | 5 #include "components/gcm_driver/crypto/encryption_header_parsers.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 { " keyid = foo ; salt = c2l4dGVlbmNvb2xieXRlcw ; rs = 1024 ", | 35 { " keyid = foo ; salt = c2l4dGVlbmNvb2xieXRlcw ; rs = 1024 ", |
| 36 "foo", "sixteencoolbytes", 1024 }, | 36 "foo", "sixteencoolbytes", 1024 }, |
| 37 { "keyid=foo", "foo", "", kDefaultRecordSize }, | 37 { "keyid=foo", "foo", "", kDefaultRecordSize }, |
| 38 { "keyid=foo;", "foo", "", kDefaultRecordSize }, | 38 { "keyid=foo;", "foo", "", kDefaultRecordSize }, |
| 39 { "keyid=\"foo\"", "foo", "", kDefaultRecordSize }, | 39 { "keyid=\"foo\"", "foo", "", kDefaultRecordSize }, |
| 40 { "keyid='foo'", "foo", "", kDefaultRecordSize }, | 40 { "keyid='foo'", "foo", "", kDefaultRecordSize }, |
| 41 { "salt=c2l4dGVlbmNvb2xieXRlcw", | 41 { "salt=c2l4dGVlbmNvb2xieXRlcw", |
| 42 "", "sixteencoolbytes", kDefaultRecordSize }, | 42 "", "sixteencoolbytes", kDefaultRecordSize }, |
| 43 { "rs=2048", "", "", 2048 }, | 43 { "rs=2048", "", "", 2048 }, |
| 44 { "keyid=foo;someothervalue=1;rs=42", "foo", "", 42 }, | 44 { "keyid=foo;someothervalue=1;rs=42", "foo", "", 42 }, |
| 45 { "keyid=foo;keyid=bar", "bar", "", kDefaultRecordSize }, | |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 for (size_t i = 0; i < arraysize(expected_results); i++) { | 47 for (size_t i = 0; i < arraysize(expected_results); i++) { |
| 49 SCOPED_TRACE(i); | 48 SCOPED_TRACE(i); |
| 50 | 49 |
| 51 std::string header(expected_results[i].header); | 50 std::string header(expected_results[i].header); |
| 52 | 51 |
| 53 EncryptionHeaderIterator iterator(header.begin(), header.end()); | 52 EncryptionHeaderIterator iterator(header.begin(), header.end()); |
| 54 ASSERT_TRUE(iterator.GetNext()); | 53 ASSERT_TRUE(iterator.GetNext()); |
| 55 | 54 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 const char* const expected_failures[] = { | 108 const char* const expected_failures[] = { |
| 110 // Values in the name-value pairs are not optional. | 109 // Values in the name-value pairs are not optional. |
| 111 "keyid", | 110 "keyid", |
| 112 "keyid=", | 111 "keyid=", |
| 113 "keyid=foo;keyid", | 112 "keyid=foo;keyid", |
| 114 "salt", | 113 "salt", |
| 115 "salt=", | 114 "salt=", |
| 116 "rs", | 115 "rs", |
| 117 "rs=", | 116 "rs=", |
| 118 | 117 |
| 118 // Supplying the same name multiple times in the same value is invalid. |
| 119 "keyid=foo;keyid=bar", |
| 120 "keyid=foo;bar=baz;keyid=qux", |
| 121 |
| 119 // The salt must be a URL-safe base64 decodable string. | 122 // The salt must be a URL-safe base64 decodable string. |
| 120 "salt=YmV/2ZXJ-sMDA", | 123 "salt=YmV/2ZXJ-sMDA", |
| 121 "salt=dHdlbHZlY29vbGJ5dGVz=====", | 124 "salt=dHdlbHZlY29vbGJ5dGVz=====", |
| 122 "salt=c2l4dGVlbmNvb2xieXRlcw;salt=123$xyz", | 125 "salt=c2l4dGVlbmNvb2xieXRlcw;salt=123$xyz", |
| 123 "salt=123$xyz", | 126 "salt=123$xyz", |
| 124 | 127 |
| 125 // The record size must be a positive decimal integer greater than one that | 128 // The record size must be a positive decimal integer greater than one that |
| 126 // does not start with a plus. | 129 // does not start with a plus. |
| 127 "rs=0", | 130 "rs=0", |
| 128 "rs=0x13", | 131 "rs=0x13", |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 "foo", "sixteencoolbytes", "twelvecoolbytes" }, | 183 "foo", "sixteencoolbytes", "twelvecoolbytes" }, |
| 181 { "KEYID=foo;AESGCM128=c2l4dGVlbmNvb2xieXRlcw;DH=dHdlbHZlY29vbGJ5dGVz", | 184 { "KEYID=foo;AESGCM128=c2l4dGVlbmNvb2xieXRlcw;DH=dHdlbHZlY29vbGJ5dGVz", |
| 182 "foo", "sixteencoolbytes", "twelvecoolbytes" }, | 185 "foo", "sixteencoolbytes", "twelvecoolbytes" }, |
| 183 { "keyid=foo", "foo", "", "" }, | 186 { "keyid=foo", "foo", "", "" }, |
| 184 { "aesgcm128=c2l4dGVlbmNvb2xieXRlcw", "", "sixteencoolbytes", "" }, | 187 { "aesgcm128=c2l4dGVlbmNvb2xieXRlcw", "", "sixteencoolbytes", "" }, |
| 185 { "aesgcm128=\"c2l4dGVlbmNvb2xieXRlcw\"", "", "sixteencoolbytes", "" }, | 188 { "aesgcm128=\"c2l4dGVlbmNvb2xieXRlcw\"", "", "sixteencoolbytes", "" }, |
| 186 { "aesgcm128='c2l4dGVlbmNvb2xieXRlcw'", "", "sixteencoolbytes", "" }, | 189 { "aesgcm128='c2l4dGVlbmNvb2xieXRlcw'", "", "sixteencoolbytes", "" }, |
| 187 { "dh=dHdlbHZlY29vbGJ5dGVz", "", "", "twelvecoolbytes" }, | 190 { "dh=dHdlbHZlY29vbGJ5dGVz", "", "", "twelvecoolbytes" }, |
| 188 { "keyid=foo;someothervalue=bar;aesgcm128=dHdlbHZlY29vbGJ5dGVz", | 191 { "keyid=foo;someothervalue=bar;aesgcm128=dHdlbHZlY29vbGJ5dGVz", |
| 189 "foo", "twelvecoolbytes", "" }, | 192 "foo", "twelvecoolbytes", "" }, |
| 190 { "keyid=foo;keyid=bar", "bar", "", "" }, | |
| 191 }; | 193 }; |
| 192 | 194 |
| 193 for (size_t i = 0; i < arraysize(expected_results); i++) { | 195 for (size_t i = 0; i < arraysize(expected_results); i++) { |
| 194 SCOPED_TRACE(i); | 196 SCOPED_TRACE(i); |
| 195 | 197 |
| 196 std::string header(expected_results[i].header); | 198 std::string header(expected_results[i].header); |
| 197 | 199 |
| 198 CryptoKeyHeaderIterator iterator(header.begin(), header.end()); | 200 CryptoKeyHeaderIterator iterator(header.begin(), header.end()); |
| 199 ASSERT_TRUE(iterator.GetNext()); | 201 ASSERT_TRUE(iterator.GetNext()); |
| 200 | 202 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 const char* const expected_failures[] = { | 257 const char* const expected_failures[] = { |
| 256 // Values in the name-value pairs are not optional. | 258 // Values in the name-value pairs are not optional. |
| 257 "keyid", | 259 "keyid", |
| 258 "keyid=", | 260 "keyid=", |
| 259 "keyid=foo;keyid", | 261 "keyid=foo;keyid", |
| 260 "aesgcm128", | 262 "aesgcm128", |
| 261 "aesgcm128=", | 263 "aesgcm128=", |
| 262 "dh", | 264 "dh", |
| 263 "dh=", | 265 "dh=", |
| 264 | 266 |
| 267 // Supplying the same name multiple times in the same value is invalid. |
| 268 "keyid=foo;keyid=bar", |
| 269 "keyid=foo;bar=baz;keyid=qux", |
| 270 |
| 265 // The "aesgcm128" parameter must be a URL-safe base64 decodable string. | 271 // The "aesgcm128" parameter must be a URL-safe base64 decodable string. |
| 266 "aesgcm128=123$xyz", | 272 "aesgcm128=123$xyz", |
| 267 "aesgcm128=foobar;aesgcm128=123$xyz", | 273 "aesgcm128=foobar;aesgcm128=123$xyz", |
| 268 | 274 |
| 269 // The "dh" parameter must be a URL-safe base64 decodable string. | 275 // The "dh" parameter must be a URL-safe base64 decodable string. |
| 270 "dh=YmV/2ZXJ-sMDA", | 276 "dh=YmV/2ZXJ-sMDA", |
| 271 "dh=dHdlbHZlY29vbGJ5dGVz=====", | 277 "dh=dHdlbHZlY29vbGJ5dGVz=====", |
| 272 "dh=123$xyz", | 278 "dh=123$xyz", |
| 273 }; | 279 }; |
| 274 | 280 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 ASSERT_FALSE(crypto_key_iterator.GetNext()); | 368 ASSERT_FALSE(crypto_key_iterator.GetNext()); |
| 363 | 369 |
| 364 EXPECT_EQ(0u, crypto_key_iterator.keyid().size()); | 370 EXPECT_EQ(0u, crypto_key_iterator.keyid().size()); |
| 365 EXPECT_EQ(0u, crypto_key_iterator.aesgcm128().size()); | 371 EXPECT_EQ(0u, crypto_key_iterator.aesgcm128().size()); |
| 366 EXPECT_EQ(0u, crypto_key_iterator.dh().size()); | 372 EXPECT_EQ(0u, crypto_key_iterator.dh().size()); |
| 367 } | 373 } |
| 368 | 374 |
| 369 } // namespace | 375 } // namespace |
| 370 | 376 |
| 371 } // namespace gcm | 377 } // namespace gcm |
| OLD | NEW |