- Timestamp:
- Oct 10, 2007 11:37:56 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util-test/encryption.c
r1266 r1488 466 466 467 467 468 /* 469 * Base64 test vectors (RFC 4648) 470 */ 471 static struct base64_test_vec 472 { 473 const char *base256; 474 const char *base64; 475 } base64_test_vec[] = 476 { 477 { 478 "", 479 "" 480 }, 481 { 482 "f", 483 "Zg==" 484 }, 485 { 486 "fo", 487 "Zm8=" 488 }, 489 { 490 "foo", 491 "Zm9v" 492 }, 493 { 494 "foob", 495 "Zm9vYg==" 496 }, 497 { 498 "fooba", 499 "Zm9vYmE=", 500 }, 501 { 502 "foobar", 503 "Zm9vYmFy" 504 }, 505 { 506 "\x14\xfb\x9c\x03\xd9\x7e", 507 "FPucA9l+" 508 }, 509 { 510 "\x14\xfb\x9c\x03\xd9", 511 "FPucA9k=" 512 }, 513 { 514 "\x14\xfb\x9c\x03", 515 "FPucAw==" 516 } 517 }; 518 519 520 static int base64_test(void) 521 { 522 unsigned i; 523 char output[80]; 524 pj_status_t rc; 525 526 PJ_LOG(3, (THIS_FILE, " base64 test..")); 527 528 for (i=0; i<PJ_ARRAY_SIZE(base64_test_vec); ++i) { 529 /* Encode test */ 530 pj_str_t input; 531 int out_len = sizeof(output); 532 533 rc = pj_base64_encode(base64_test_vec[i].base256, 534 strlen(base64_test_vec[i].base256), 535 output, &out_len); 536 if (rc != PJ_SUCCESS) 537 return -90; 538 539 if (out_len != strlen(base64_test_vec[i].base64)) 540 return -91; 541 542 output[out_len] = '\0'; 543 if (strcmp(output, base64_test_vec[i].base64) != 0) 544 return -92; 545 546 /* Decode test */ 547 out_len = sizeof(output); 548 input.ptr = base64_test_vec[i].base64; 549 input.slen = strlen(base64_test_vec[i].base64); 550 rc = pj_base64_decode(&input, (pj_uint8_t*)output, &out_len); 551 if (rc != PJ_SUCCESS) 552 return -95; 553 554 if (out_len != strlen(base64_test_vec[i].base256)) 555 return -96; 556 557 output[out_len] = '\0'; 558 559 if (strcmp(output, base64_test_vec[i].base256) != 0) 560 return -97; 561 } 562 563 return 0; 564 } 565 566 468 567 int encryption_test() 469 568 { 470 569 int rc; 570 571 rc = base64_test(); 572 if (rc != 0) 573 return rc; 471 574 472 575 rc = sha1_test1();
Note: See TracChangeset
for help on using the changeset viewer.