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

Side by Side Diff: net/quic/crypto/channel_id_test.cc

Issue 612323013: QUIC - (no behavior change) s/NULL/nullptr/g in .../quic/... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « net/quic/crypto/channel_id_openssl.cc ('k') | net/quic/crypto/crypto_framer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/quic/crypto/channel_id.h" 5 #include "net/quic/crypto/channel_id.h"
6 6
7 #include "net/quic/test_tools/crypto_test_utils.h" 7 #include "net/quic/test_tools/crypto_test_utils.h"
8 #include "net/quic/test_tools/quic_test_utils.h" 8 #include "net/quic/test_tools/quic_test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } // namespace 189 } // namespace
190 190
191 // A known answer test for ChannelIDVerifier. 191 // A known answer test for ChannelIDVerifier.
192 TEST(ChannelIDTest, VerifyKnownAnswerTest) { 192 TEST(ChannelIDTest, VerifyKnownAnswerTest) {
193 string msg; 193 string msg;
194 string qx; 194 string qx;
195 string qy; 195 string qy;
196 string r; 196 string r;
197 string s; 197 string s;
198 198
199 for (size_t i = 0; test_vector[i].msg != NULL; i++) { 199 for (size_t i = 0; test_vector[i].msg != nullptr; i++) {
200 SCOPED_TRACE(i); 200 SCOPED_TRACE(i);
201 // Decode the test vector. 201 // Decode the test vector.
202 ASSERT_TRUE(DecodeHexString(test_vector[i].msg, &msg)); 202 ASSERT_TRUE(DecodeHexString(test_vector[i].msg, &msg));
203 ASSERT_TRUE(DecodeHexString(test_vector[i].qx, &qx)); 203 ASSERT_TRUE(DecodeHexString(test_vector[i].qx, &qx));
204 ASSERT_TRUE(DecodeHexString(test_vector[i].qy, &qy)); 204 ASSERT_TRUE(DecodeHexString(test_vector[i].qy, &qy));
205 ASSERT_TRUE(DecodeHexString(test_vector[i].r, &r)); 205 ASSERT_TRUE(DecodeHexString(test_vector[i].r, &r));
206 ASSERT_TRUE(DecodeHexString(test_vector[i].s, &s)); 206 ASSERT_TRUE(DecodeHexString(test_vector[i].s, &s));
207 207
208 string key = qx + qy; 208 string key = qx + qy;
209 string signature = r + s; 209 string signature = r + s;
(...skipping 10 matching lines...) Expand all
220 } 220 }
221 221
222 TEST(ChannelIDTest, SignAndVerify) { 222 TEST(ChannelIDTest, SignAndVerify) {
223 scoped_ptr<ChannelIDSource> source( 223 scoped_ptr<ChannelIDSource> source(
224 CryptoTestUtils::ChannelIDSourceForTesting()); 224 CryptoTestUtils::ChannelIDSourceForTesting());
225 225
226 const string signed_data = "signed data"; 226 const string signed_data = "signed data";
227 const string hostname = "foo.example.com"; 227 const string hostname = "foo.example.com";
228 scoped_ptr<ChannelIDKey> channel_id_key; 228 scoped_ptr<ChannelIDKey> channel_id_key;
229 QuicAsyncStatus status = 229 QuicAsyncStatus status =
230 source->GetChannelIDKey(hostname, &channel_id_key, NULL); 230 source->GetChannelIDKey(hostname, &channel_id_key, nullptr);
231 ASSERT_EQ(QUIC_SUCCESS, status); 231 ASSERT_EQ(QUIC_SUCCESS, status);
232 232
233 string signature; 233 string signature;
234 ASSERT_TRUE(channel_id_key->Sign(signed_data, &signature)); 234 ASSERT_TRUE(channel_id_key->Sign(signed_data, &signature));
235 235
236 string key = channel_id_key->SerializeKey(); 236 string key = channel_id_key->SerializeKey();
237 EXPECT_TRUE(ChannelIDVerifier::Verify(key, signed_data, signature)); 237 EXPECT_TRUE(ChannelIDVerifier::Verify(key, signed_data, signature));
238 238
239 EXPECT_FALSE(ChannelIDVerifier::Verify("a" + key, signed_data, signature)); 239 EXPECT_FALSE(ChannelIDVerifier::Verify("a" + key, signed_data, signature));
240 EXPECT_FALSE(ChannelIDVerifier::Verify(key, "a" + signed_data, signature)); 240 EXPECT_FALSE(ChannelIDVerifier::Verify(key, "a" + signed_data, signature));
241 241
242 scoped_ptr<char[]> bad_key(new char[key.size()]); 242 scoped_ptr<char[]> bad_key(new char[key.size()]);
243 memcpy(bad_key.get(), key.data(), key.size()); 243 memcpy(bad_key.get(), key.data(), key.size());
244 bad_key[1] ^= 0x80; 244 bad_key[1] ^= 0x80;
245 EXPECT_FALSE(ChannelIDVerifier::Verify( 245 EXPECT_FALSE(ChannelIDVerifier::Verify(
246 string(bad_key.get(), key.size()), signed_data, signature)); 246 string(bad_key.get(), key.size()), signed_data, signature));
247 247
248 scoped_ptr<char[]> bad_signature(new char[signature.size()]); 248 scoped_ptr<char[]> bad_signature(new char[signature.size()]);
249 memcpy(bad_signature.get(), signature.data(), signature.size()); 249 memcpy(bad_signature.get(), signature.data(), signature.size());
250 bad_signature[1] ^= 0x80; 250 bad_signature[1] ^= 0x80;
251 EXPECT_FALSE(ChannelIDVerifier::Verify( 251 EXPECT_FALSE(ChannelIDVerifier::Verify(
252 key, signed_data, string(bad_signature.get(), signature.size()))); 252 key, signed_data, string(bad_signature.get(), signature.size())));
253 253
254 EXPECT_FALSE(ChannelIDVerifier::Verify( 254 EXPECT_FALSE(ChannelIDVerifier::Verify(
255 key, "wrong signed data", signature)); 255 key, "wrong signed data", signature));
256 } 256 }
257 257
258 } // namespace test 258 } // namespace test
259 } // namespace net 259 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/channel_id_openssl.cc ('k') | net/quic/crypto/crypto_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698