OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 size_t szdest) { | 332 size_t szdest) { |
333 std::string escaped; | 333 std::string escaped; |
334 Base64::EncodeFromArray((const char *)src, szsrc, &escaped); | 334 Base64::EncodeFromArray((const char *)src, szsrc, &escaped); |
335 memcpy(dest, escaped.data(), min(escaped.size(), szdest)); | 335 memcpy(dest, escaped.data(), min(escaped.size(), szdest)); |
336 return escaped.size(); | 336 return escaped.size(); |
337 } | 337 } |
338 | 338 |
339 size_t Base64Unescape(const char *src, size_t szsrc, char *dest, | 339 size_t Base64Unescape(const char *src, size_t szsrc, char *dest, |
340 size_t szdest) { | 340 size_t szdest) { |
341 std::string unescaped; | 341 std::string unescaped; |
342 EXPECT_TRUE(Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, &unescaped, | 342 EXPECT_TRUE( |
343 NULL)); | 343 Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, &unescaped, nullptr)); |
344 memcpy(dest, unescaped.data(), min(unescaped.size(), szdest)); | 344 memcpy(dest, unescaped.data(), min(unescaped.size(), szdest)); |
345 return unescaped.size(); | 345 return unescaped.size(); |
346 } | 346 } |
347 | 347 |
348 size_t Base64Unescape(const char *src, size_t szsrc, std::string *s) { | 348 size_t Base64Unescape(const char *src, size_t szsrc, std::string *s) { |
349 EXPECT_TRUE(Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, s, NULL)); | 349 EXPECT_TRUE(Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, s, nullptr)); |
350 return s->size(); | 350 return s->size(); |
351 } | 351 } |
352 | 352 |
353 TEST(Base64, EncodeDecodeBattery) { | 353 TEST(Base64, EncodeDecodeBattery) { |
354 LOG(LS_VERBOSE) << "Testing base-64"; | 354 LOG(LS_VERBOSE) << "Testing base-64"; |
355 | 355 |
356 size_t i; | 356 size_t i; |
357 | 357 |
358 // Check the short strings; this tests the math (and boundaries) | 358 // Check the short strings; this tests the math (and boundaries) |
359 for( i = 0; i < sizeof(base64_tests) / sizeof(base64_tests[0]); ++i ) { | 359 for( i = 0; i < sizeof(base64_tests) / sizeof(base64_tests[0]); ++i ) { |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 // The table looks like this: | 988 // The table looks like this: |
989 // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" | 989 // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
990 char next_char; | 990 char next_char; |
991 EXPECT_TRUE(Base64::GetNextBase64Char('A', &next_char)); | 991 EXPECT_TRUE(Base64::GetNextBase64Char('A', &next_char)); |
992 EXPECT_EQ('B', next_char); | 992 EXPECT_EQ('B', next_char); |
993 EXPECT_TRUE(Base64::GetNextBase64Char('Z', &next_char)); | 993 EXPECT_TRUE(Base64::GetNextBase64Char('Z', &next_char)); |
994 EXPECT_EQ('a', next_char); | 994 EXPECT_EQ('a', next_char); |
995 EXPECT_TRUE(Base64::GetNextBase64Char('/', &next_char)); | 995 EXPECT_TRUE(Base64::GetNextBase64Char('/', &next_char)); |
996 EXPECT_EQ('A', next_char); | 996 EXPECT_EQ('A', next_char); |
997 EXPECT_FALSE(Base64::GetNextBase64Char('&', &next_char)); | 997 EXPECT_FALSE(Base64::GetNextBase64Char('&', &next_char)); |
998 EXPECT_FALSE(Base64::GetNextBase64Char('Z', NULL)); | 998 EXPECT_FALSE(Base64::GetNextBase64Char('Z', nullptr)); |
999 } | 999 } |
OLD | NEW |