Merge pull request #8742 from thomasvl/cypher_to_cipher

cypher -> cipher for the codespell workflow.
pull/8743/head
Matt Fowles Kulukundis 4 years ago committed by GitHub
commit c67c6cebc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGES.txt
  2. 6
      src/google/protobuf/stubs/strutil.cc
  3. 72
      src/google/protobuf/stubs/strutil_unittest.cc

@ -277,7 +277,7 @@
collection directly instead of using the other methods of the BaseContainer. collection directly instead of using the other methods of the BaseContainer.
* MessageFactory.CreateProtoype can be overridden to customize class creation. * MessageFactory.CreateProtoype can be overridden to customize class creation.
* Fix PyUnknownFields memory leak (#7928) * Fix PyUnknownFields memory leak (#7928)
* Add macOS big sur compatibility (#8126) * Add macOS Big Sur compatibility (#8126)
JavaScript JavaScript
* Generate `getDescriptor` methods with `*` as their `this` type. * Generate `getDescriptor` methods with `*` as their `this` type.

@ -2101,7 +2101,7 @@ int Base64EscapeInternal(const unsigned char *src, int szsrc,
char *limit_dest = dest + szdest; char *limit_dest = dest + szdest;
const unsigned char *limit_src = src + szsrc; const unsigned char *limit_src = src + szsrc;
// Three bytes of data encodes to four characters of cyphertext. // Three bytes of data encodes to four characters of ciphertext.
// So we can pump through three-byte chunks atomically. // So we can pump through three-byte chunks atomically.
while (cur_src < limit_src - 3) { // keep going as long as we have >= 32 bits while (cur_src < limit_src - 3) { // keep going as long as we have >= 32 bits
uint32 in = BigEndian::Load32(cur_src) >> 8; uint32 in = BigEndian::Load32(cur_src) >> 8;
@ -2128,7 +2128,7 @@ int Base64EscapeInternal(const unsigned char *src, int szsrc,
break; break;
case 1: { case 1: {
// One byte left: this encodes to two characters, and (optionally) // One byte left: this encodes to two characters, and (optionally)
// two pad characters to round out the four-character cypherblock. // two pad characters to round out the four-character cipherblock.
if ((szdest -= 2) < 0) return 0; if ((szdest -= 2) < 0) return 0;
uint32 in = cur_src[0]; uint32 in = cur_src[0];
cur_dest[0] = base64[in >> 2]; cur_dest[0] = base64[in >> 2];
@ -2145,7 +2145,7 @@ int Base64EscapeInternal(const unsigned char *src, int szsrc,
} }
case 2: { case 2: {
// Two bytes left: this encodes to three characters, and (optionally) // Two bytes left: this encodes to three characters, and (optionally)
// one pad character to round out the four-character cypherblock. // one pad character to round out the four-character cipherblock.
if ((szdest -= 3) < 0) return 0; if ((szdest -= 3) < 0) return 0;
uint32 in = BigEndian::Load16(cur_src); uint32 in = BigEndian::Load16(cur_src);
cur_dest[0] = base64[in >> 10]; cur_dest[0] = base64[in >> 10];

@ -83,7 +83,7 @@ TEST(StringUtilityTest, ImmuneToLocales) {
static struct { static struct {
int plain_length; int plain_length;
const char* plaintext; const char* plaintext;
const char* cyphertext; const char* ciphertext;
} base64_tests[] = { } base64_tests[] = {
// Empty string. // Empty string.
{ 0, "", ""}, { 0, "", ""},
@ -343,10 +343,10 @@ static struct {
static struct { static struct {
const char* plaintext; const char* plaintext;
const char* cyphertext; const char* ciphertext;
} base64_strings[] = { } base64_strings[] = {
// Some google quotes // Some google quotes
// Cyphertext created with "uuencode (GNU sharutils) 4.6.3" // Ciphertext created with "uuencode (GNU sharutils) 4.6.3"
// (Note that we're testing the websafe encoding, though, so if // (Note that we're testing the websafe encoding, though, so if
// you add messages, be sure to run "tr -- '+/' '-_'" on the output) // you add messages, be sure to run "tr -- '+/' '-_'" on the output)
{ "I was always good at math and science, and I never realized " { "I was always good at math and science, and I never realized "
@ -441,7 +441,7 @@ TEST(Base64, EscapeAndUnescape) {
int encode_length; int encode_length;
char decode_buffer[100]; char decode_buffer[100];
int decode_length; int decode_length;
int cypher_length; int cipher_length;
std::string decode_str; std::string decode_str;
const unsigned char* unsigned_plaintext = const unsigned char* unsigned_plaintext =
@ -450,7 +450,7 @@ TEST(Base64, EscapeAndUnescape) {
StringPiece plaintext(base64_tests[i].plaintext, StringPiece plaintext(base64_tests[i].plaintext,
base64_tests[i].plain_length); base64_tests[i].plain_length);
cypher_length = strlen(base64_tests[i].cyphertext); cipher_length = strlen(base64_tests[i].ciphertext);
// The basic escape function: // The basic escape function:
memset(encode_buffer, 0, sizeof(encode_buffer)); memset(encode_buffer, 0, sizeof(encode_buffer));
@ -459,30 +459,30 @@ TEST(Base64, EscapeAndUnescape) {
encode_buffer, encode_buffer,
sizeof(encode_buffer)); sizeof(encode_buffer));
// Is it of the expected length? // Is it of the expected length?
EXPECT_EQ(encode_length, cypher_length); EXPECT_EQ(encode_length, cipher_length);
// Would it have been okay to allocate only CalculateBase64EscapeLen()? // Would it have been okay to allocate only CalculateBase64EscapeLen()?
EXPECT_EQ(CalculateBase64EscapedLen(base64_tests[i].plain_length), EXPECT_EQ(CalculateBase64EscapedLen(base64_tests[i].plain_length),
encode_length); encode_length);
// Is it the expected encoded value? // Is it the expected encoded value?
ASSERT_STREQ(encode_buffer, base64_tests[i].cyphertext); ASSERT_STREQ(encode_buffer, base64_tests[i].ciphertext);
// If we encode it into a buffer of exactly the right length... // If we encode it into a buffer of exactly the right length...
memset(encode_buffer, 0, sizeof(encode_buffer)); memset(encode_buffer, 0, sizeof(encode_buffer));
encode_length = Base64Escape(unsigned_plaintext, encode_length = Base64Escape(unsigned_plaintext,
base64_tests[i].plain_length, base64_tests[i].plain_length,
encode_buffer, encode_buffer,
cypher_length); cipher_length);
// Is it still of the expected length? // Is it still of the expected length?
EXPECT_EQ(encode_length, cypher_length); EXPECT_EQ(encode_length, cipher_length);
// And is the value still correct? (i.e., not losing the last byte) // And is the value still correct? (i.e., not losing the last byte)
EXPECT_STREQ(encode_buffer, base64_tests[i].cyphertext); EXPECT_STREQ(encode_buffer, base64_tests[i].ciphertext);
// If we decode it back: // If we decode it back:
decode_str.clear(); decode_str.clear();
EXPECT_TRUE(Base64Unescape( EXPECT_TRUE(Base64Unescape(
StringPiece(encode_buffer, cypher_length), &decode_str)); StringPiece(encode_buffer, cipher_length), &decode_str));
// Is it of the expected length? // Is it of the expected length?
EXPECT_EQ(base64_tests[i].plain_length, decode_str.length()); EXPECT_EQ(base64_tests[i].plain_length, decode_str.length());
@ -495,11 +495,11 @@ TEST(Base64, EscapeAndUnescape) {
Base64Escape( Base64Escape(
std::string(base64_tests[i].plaintext, base64_tests[i].plain_length), std::string(base64_tests[i].plaintext, base64_tests[i].plain_length),
&encoded); &encoded);
EXPECT_EQ(encoded, std::string(encode_buffer, cypher_length)); EXPECT_EQ(encoded, std::string(encode_buffer, cipher_length));
std::string decoded("this junk should be ignored"); std::string decoded("this junk should be ignored");
EXPECT_TRUE(Base64Unescape( EXPECT_TRUE(Base64Unescape(
StringPiece(encode_buffer, cypher_length), &decoded)); StringPiece(encode_buffer, cipher_length), &decoded));
EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
@ -578,7 +578,7 @@ TEST(Base64, EscapeAndUnescape) {
char websafe[100]; char websafe[100];
memset(websafe, 0, sizeof(websafe)); memset(websafe, 0, sizeof(websafe));
strncpy(websafe, base64_tests[i].cyphertext, cypher_length); strncpy(websafe, base64_tests[i].ciphertext, cipher_length);
for (int c = 0; c < sizeof(websafe); ++c) { for (int c = 0; c < sizeof(websafe); ++c) {
if ('+' == websafe[c]) { websafe[c] = '-'; } if ('+' == websafe[c]) { websafe[c] = '-'; }
if ('/' == websafe[c]) { websafe[c] = '_'; } if ('/' == websafe[c]) { websafe[c] = '_'; }
@ -592,7 +592,7 @@ TEST(Base64, EscapeAndUnescape) {
sizeof(encode_buffer), sizeof(encode_buffer),
true); true);
// Is it of the expected length? // Is it of the expected length?
EXPECT_EQ(encode_length, cypher_length); EXPECT_EQ(encode_length, cipher_length);
EXPECT_EQ( EXPECT_EQ(
CalculateBase64EscapedLen(base64_tests[i].plain_length, true), CalculateBase64EscapedLen(base64_tests[i].plain_length, true),
encode_length); encode_length);
@ -605,10 +605,10 @@ TEST(Base64, EscapeAndUnescape) {
encode_length = WebSafeBase64Escape(unsigned_plaintext, encode_length = WebSafeBase64Escape(unsigned_plaintext,
base64_tests[i].plain_length, base64_tests[i].plain_length,
encode_buffer, encode_buffer,
cypher_length, cipher_length,
true); true);
// Is it still of the expected length? // Is it still of the expected length?
EXPECT_EQ(encode_length, cypher_length); EXPECT_EQ(encode_length, cipher_length);
// And is the value still correct? (i.e., not losing the last byte) // And is the value still correct? (i.e., not losing the last byte)
EXPECT_STREQ(encode_buffer, websafe); EXPECT_STREQ(encode_buffer, websafe);
@ -618,13 +618,13 @@ TEST(Base64, EscapeAndUnescape) {
WebSafeBase64Escape( WebSafeBase64Escape(
unsigned_plaintext, base64_tests[i].plain_length, unsigned_plaintext, base64_tests[i].plain_length,
&encoded, true); &encoded, true);
EXPECT_EQ(encoded.size(), cypher_length); EXPECT_EQ(encoded.size(), cipher_length);
EXPECT_STREQ(encoded.c_str(), websafe); EXPECT_STREQ(encoded.c_str(), websafe);
// If we decode it back: // If we decode it back:
memset(decode_buffer, 0, sizeof(decode_buffer)); memset(decode_buffer, 0, sizeof(decode_buffer));
decode_length = WebSafeBase64Unescape(encode_buffer, decode_length = WebSafeBase64Unescape(encode_buffer,
cypher_length, cipher_length,
decode_buffer, decode_buffer,
sizeof(decode_buffer)); sizeof(decode_buffer));
@ -638,7 +638,7 @@ TEST(Base64, EscapeAndUnescape) {
// If we decode it into a buffer of exactly the right length... // If we decode it into a buffer of exactly the right length...
memset(decode_buffer, 0, sizeof(decode_buffer)); memset(decode_buffer, 0, sizeof(decode_buffer));
decode_length = WebSafeBase64Unescape(encode_buffer, decode_length = WebSafeBase64Unescape(encode_buffer,
cypher_length, cipher_length,
decode_buffer, decode_buffer,
decode_length); decode_length);
@ -650,14 +650,14 @@ TEST(Base64, EscapeAndUnescape) {
memcmp(decode_buffer, base64_tests[i].plaintext, decode_length)); memcmp(decode_buffer, base64_tests[i].plaintext, decode_length));
// Try using '.' for the pad character. // Try using '.' for the pad character.
for (int c = cypher_length - 1; c >= 0 && '=' == encode_buffer[c]; --c) { for (int c = cipher_length - 1; c >= 0 && '=' == encode_buffer[c]; --c) {
encode_buffer[c] = '.'; encode_buffer[c] = '.';
} }
// If we decode it back: // If we decode it back:
memset(decode_buffer, 0, sizeof(decode_buffer)); memset(decode_buffer, 0, sizeof(decode_buffer));
decode_length = WebSafeBase64Unescape(encode_buffer, decode_length = WebSafeBase64Unescape(encode_buffer,
cypher_length, cipher_length,
decode_buffer, decode_buffer,
sizeof(decode_buffer)); sizeof(decode_buffer));
@ -671,7 +671,7 @@ TEST(Base64, EscapeAndUnescape) {
// If we decode it into a buffer of exactly the right length... // If we decode it into a buffer of exactly the right length...
memset(decode_buffer, 0, sizeof(decode_buffer)); memset(decode_buffer, 0, sizeof(decode_buffer));
decode_length = WebSafeBase64Unescape(encode_buffer, decode_length = WebSafeBase64Unescape(encode_buffer,
cypher_length, cipher_length,
decode_buffer, decode_buffer,
decode_length); decode_length);
@ -685,7 +685,7 @@ TEST(Base64, EscapeAndUnescape) {
// Let's try the string version of the decoder // Let's try the string version of the decoder
decoded = "this junk should be ignored"; decoded = "this junk should be ignored";
EXPECT_TRUE(WebSafeBase64Unescape( EXPECT_TRUE(WebSafeBase64Unescape(
StringPiece(encode_buffer, cypher_length), &decoded)); StringPiece(encode_buffer, cipher_length), &decoded));
EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
@ -695,7 +695,7 @@ TEST(Base64, EscapeAndUnescape) {
for (int c = 0; c < sizeof(websafe); ++c) { for (int c = 0; c < sizeof(websafe); ++c) {
if ('=' == websafe[c]) { if ('=' == websafe[c]) {
websafe[c] = '\0'; websafe[c] = '\0';
cypher_length = c; cipher_length = c;
break; break;
} }
} }
@ -708,7 +708,7 @@ TEST(Base64, EscapeAndUnescape) {
sizeof(encode_buffer), sizeof(encode_buffer),
false); false);
// Is it of the expected length? // Is it of the expected length?
EXPECT_EQ(encode_length, cypher_length); EXPECT_EQ(encode_length, cipher_length);
EXPECT_EQ( EXPECT_EQ(
CalculateBase64EscapedLen(base64_tests[i].plain_length, false), CalculateBase64EscapedLen(base64_tests[i].plain_length, false),
encode_length); encode_length);
@ -721,10 +721,10 @@ TEST(Base64, EscapeAndUnescape) {
encode_length = WebSafeBase64Escape(unsigned_plaintext, encode_length = WebSafeBase64Escape(unsigned_plaintext,
base64_tests[i].plain_length, base64_tests[i].plain_length,
encode_buffer, encode_buffer,
cypher_length, cipher_length,
false); false);
// Is it still of the expected length? // Is it still of the expected length?
EXPECT_EQ(encode_length, cypher_length); EXPECT_EQ(encode_length, cipher_length);
// And is the value still correct? (i.e., not losing the last byte) // And is the value still correct? (i.e., not losing the last byte)
EXPECT_STREQ(encode_buffer, websafe); EXPECT_STREQ(encode_buffer, websafe);
@ -733,13 +733,13 @@ TEST(Base64, EscapeAndUnescape) {
std::string plain(base64_tests[i].plaintext, base64_tests[i].plain_length); std::string plain(base64_tests[i].plaintext, base64_tests[i].plain_length);
encoded = "this junk should be ignored"; encoded = "this junk should be ignored";
WebSafeBase64Escape(plain, &encoded); WebSafeBase64Escape(plain, &encoded);
EXPECT_EQ(encoded.size(), cypher_length); EXPECT_EQ(encoded.size(), cipher_length);
EXPECT_STREQ(encoded.c_str(), websafe); EXPECT_STREQ(encoded.c_str(), websafe);
// If we decode it back: // If we decode it back:
memset(decode_buffer, 0, sizeof(decode_buffer)); memset(decode_buffer, 0, sizeof(decode_buffer));
decode_length = WebSafeBase64Unescape(encode_buffer, decode_length = WebSafeBase64Unescape(encode_buffer,
cypher_length, cipher_length,
decode_buffer, decode_buffer,
sizeof(decode_buffer)); sizeof(decode_buffer));
@ -753,7 +753,7 @@ TEST(Base64, EscapeAndUnescape) {
// If we decode it into a buffer of exactly the right length... // If we decode it into a buffer of exactly the right length...
memset(decode_buffer, 0, sizeof(decode_buffer)); memset(decode_buffer, 0, sizeof(decode_buffer));
decode_length = WebSafeBase64Unescape(encode_buffer, decode_length = WebSafeBase64Unescape(encode_buffer,
cypher_length, cipher_length,
decode_buffer, decode_buffer,
decode_length); decode_length);
@ -768,7 +768,7 @@ TEST(Base64, EscapeAndUnescape) {
// Let's try the string version of the decoder // Let's try the string version of the decoder
decoded = "this junk should be ignored"; decoded = "this junk should be ignored";
EXPECT_TRUE(WebSafeBase64Unescape( EXPECT_TRUE(WebSafeBase64Unescape(
StringPiece(encode_buffer, cypher_length), &decoded)); StringPiece(encode_buffer, cipher_length), &decoded));
EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
@ -781,18 +781,18 @@ TEST(Base64, EscapeAndUnescape) {
const unsigned char* unsigned_plaintext = const unsigned char* unsigned_plaintext =
reinterpret_cast<const unsigned char*>(base64_strings[i].plaintext); reinterpret_cast<const unsigned char*>(base64_strings[i].plaintext);
int plain_length = strlen(base64_strings[i].plaintext); int plain_length = strlen(base64_strings[i].plaintext);
int cypher_length = strlen(base64_strings[i].cyphertext); int cipher_length = strlen(base64_strings[i].ciphertext);
std::vector<char> buffer(cypher_length+1); std::vector<char> buffer(cipher_length+1);
int encode_length = WebSafeBase64Escape(unsigned_plaintext, int encode_length = WebSafeBase64Escape(unsigned_plaintext,
plain_length, plain_length,
&buffer[0], &buffer[0],
buffer.size(), buffer.size(),
false); false);
EXPECT_EQ(cypher_length, encode_length); EXPECT_EQ(cipher_length, encode_length);
EXPECT_EQ( EXPECT_EQ(
CalculateBase64EscapedLen(plain_length, false), encode_length); CalculateBase64EscapedLen(plain_length, false), encode_length);
buffer[ encode_length ] = '\0'; buffer[ encode_length ] = '\0';
EXPECT_STREQ(base64_strings[i].cyphertext, &buffer[0]); EXPECT_STREQ(base64_strings[i].ciphertext, &buffer[0]);
} }
// Verify the behavior when decoding bad data // Verify the behavior when decoding bad data

Loading…
Cancel
Save