- Timestamp:
- Oct 26, 2010 11:53:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util-test/encryption.c
r2690 r3356 495 495 } 496 496 497 enum 498 { 499 ENCODE = 1, 500 DECODE = 2, 501 ENCODE_DECODE = 3 502 }; 497 503 498 504 /* … … 503 509 const char *base256; 504 510 const char *base64; 511 unsigned flag; 505 512 } base64_test_vec[] = 506 513 { 507 514 { 508 515 "", 509 "" 516 "", 517 ENCODE_DECODE 510 518 }, 511 519 { 512 520 "f", 513 "Zg==" 521 "Zg==", 522 ENCODE_DECODE 514 523 }, 515 524 { 516 525 "fo", 517 "Zm8=" 526 "Zm8=", 527 ENCODE_DECODE 518 528 }, 519 529 { 520 530 "foo", 521 "Zm9v" 531 "Zm9v", 532 ENCODE_DECODE 522 533 }, 523 534 { 524 535 "foob", 525 "Zm9vYg==" 536 "Zm9vYg==", 537 ENCODE_DECODE 526 538 }, 527 539 { 528 540 "fooba", 529 541 "Zm9vYmE=", 542 ENCODE_DECODE 530 543 }, 531 544 { 532 545 "foobar", 533 "Zm9vYmFy" 546 "Zm9vYmFy", 547 ENCODE_DECODE 534 548 }, 535 549 { 536 550 "\x14\xfb\x9c\x03\xd9\x7e", 537 "FPucA9l+" 551 "FPucA9l+", 552 ENCODE_DECODE 538 553 }, 539 554 { 540 555 "\x14\xfb\x9c\x03\xd9", 541 "FPucA9k=" 556 "FPucA9k=", 557 ENCODE_DECODE 542 558 }, 543 559 { 544 560 "\x14\xfb\x9c\x03", 545 "FPucAw==" 546 } 561 "FPucAw==", 562 ENCODE_DECODE 563 }, 564 /* with whitespaces */ 565 { 566 "foobar", 567 "Zm9v\r\nYmFy", 568 DECODE 569 }, 570 { 571 "foobar", 572 "\nZ\r\nm 9\tv\nYm\nF\ny\n", 573 DECODE 574 }, 547 575 }; 548 576 … … 557 585 558 586 for (i=0; i<PJ_ARRAY_SIZE(base64_test_vec); ++i) { 587 pj_str_t input; 588 int out_len; 589 559 590 /* Encode test */ 560 pj_str_t input;561 intout_len = sizeof(output);562 563 rc = pj_base64_encode((pj_uint8_t*)base64_test_vec[i].base256,564 strlen(base64_test_vec[i].base256),565 output, &out_len);566 if (rc != PJ_SUCCESS)567 return -90; 568 569 if (out_len != (int)strlen(base64_test_vec[i].base64))570 return -91; 571 572 output[out_len] = '\0';573 if (strcmp(output, base64_test_vec[i].base64) != 0)574 return -92;591 if (base64_test_vec[i].flag & ENCODE) { 592 out_len = sizeof(output); 593 rc = pj_base64_encode((pj_uint8_t*)base64_test_vec[i].base256, 594 strlen(base64_test_vec[i].base256), 595 output, &out_len); 596 if (rc != PJ_SUCCESS) 597 return -90; 598 599 if (out_len != (int)strlen(base64_test_vec[i].base64)) 600 return -91; 601 602 output[out_len] = '\0'; 603 if (strcmp(output, base64_test_vec[i].base64) != 0) 604 return -92; 605 } 575 606 576 607 /* Decode test */ 577 out_len = sizeof(output); 578 input.ptr = (char*)base64_test_vec[i].base64; 579 input.slen = strlen(base64_test_vec[i].base64); 580 rc = pj_base64_decode(&input, (pj_uint8_t*)output, &out_len); 581 if (rc != PJ_SUCCESS) 582 return -95; 583 584 if (out_len != (int)strlen(base64_test_vec[i].base256)) 585 return -96; 586 587 output[out_len] = '\0'; 588 589 if (strcmp(output, base64_test_vec[i].base256) != 0) 590 return -97; 608 if (base64_test_vec[i].flag & DECODE) { 609 out_len = sizeof(output); 610 input.ptr = (char*)base64_test_vec[i].base64; 611 input.slen = strlen(base64_test_vec[i].base64); 612 rc = pj_base64_decode(&input, (pj_uint8_t*)output, &out_len); 613 if (rc != PJ_SUCCESS) 614 return -95; 615 616 if (out_len != (int)strlen(base64_test_vec[i].base256)) 617 return -96; 618 619 output[out_len] = '\0'; 620 621 if (strcmp(output, base64_test_vec[i].base256) != 0) 622 return -97; 623 } 591 624 } 592 625
Note: See TracChangeset
for help on using the changeset viewer.