Changeset 5385
- Timestamp:
- 03/14/08 11:10:54 (4 months ago)
- Files:
-
- libwired/trunk/libwired/misc/wi-crypto.c (modified) (4 diffs)
- libwired/trunk/libwired/misc/wi-crypto.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/libwired/misc/wi-crypto.c
r5308 r5385 65 65 66 66 67 struct _wi_x509 { 68 wi_runtime_base_t base; 69 70 X509 *x509; 71 }; 72 73 static void _wi_x509_dealloc(wi_runtime_instance_t *); 74 static wi_string_t * _wi_x509_description(wi_runtime_instance_t *); 75 76 static wi_runtime_id_t _wi_x509_runtime_id = WI_RUNTIME_ID_NULL; 77 static wi_runtime_class_t _wi_x509_runtime_class = { 78 "wi_x509_t", 79 _wi_x509_dealloc, 80 NULL, 81 NULL, 82 _wi_x509_description, 83 NULL 84 }; 85 86 87 67 88 struct _wi_cipher { 68 89 wi_runtime_base_t base; … … 96 117 void wi_crypto_register(void) { 97 118 _wi_rsa_runtime_id = wi_runtime_register_class(&_wi_rsa_runtime_class); 119 _wi_x509_runtime_id = wi_runtime_register_class(&_wi_x509_runtime_class); 98 120 _wi_cipher_runtime_id = wi_runtime_register_class(&_wi_cipher_runtime_class); 99 121 } … … 239 261 #pragma mark - 240 262 263 void * wi_rsa_rsa(wi_rsa_t *rsa) { 264 return rsa->rsa; 265 } 266 267 268 241 269 wi_data_t * wi_rsa_public_key(wi_rsa_t *rsa) { 242 270 unsigned char *buffer; … … 369 397 370 398 return true; 399 } 400 401 402 403 #pragma mark - 404 405 wi_runtime_id_t wi_x509_runtime_id(void) { 406 return _wi_x509_runtime_id; 407 } 408 409 410 411 #pragma mark - 412 413 wi_x509_t * wi_x509_alloc(void) { 414 return wi_runtime_create_instance(_wi_x509_runtime_id, sizeof(wi_x509_t)); 415 } 416 417 418 419 wi_x509_t * wi_x509_init_with_pem_file(wi_x509_t *x509, wi_string_t *path) { 420 FILE *fp; 421 422 fp = fopen(wi_string_cstring(path), "r"); 423 424 if(!fp) { 425 wi_error_set_errno(errno); 426 427 wi_release(x509); 428 429 return NULL; 430 } 431 432 x509->x509 = PEM_read_X509(fp, NULL, NULL, NULL); 433 434 fclose(fp); 435 436 if(!x509->x509) { 437 wi_error_set_openssl_error(); 438 439 wi_release(x509); 440 441 return NULL; 442 } 443 444 return x509; 445 } 446 447 448 449 static void _wi_x509_dealloc(wi_runtime_instance_t *instance) { 450 wi_x509_t *x509 = instance; 451 452 X509_free(x509->x509); 453 } 454 455 456 457 static wi_string_t * _wi_x509_description(wi_runtime_instance_t *instance) { 458 wi_x509_t *x509 = instance; 459 460 return wi_string_with_format(WI_STR("<%@ %p>{x509 = %p}"), 461 wi_runtime_class_name(x509), 462 x509, 463 x509->x509); 464 } 465 466 467 468 #pragma mark - 469 470 void * wi_x509_x509(wi_x509_t *x509) { 471 return x509->x509; 371 472 } 372 473 libwired/trunk/libwired/misc/wi-crypto.h
r5308 r5385 45 45 46 46 typedef struct _wi_rsa wi_rsa_t; 47 typedef struct _wi_x509 wi_x509_t; 47 48 typedef struct _wi_cipher wi_cipher_t; 48 49 … … 56 57 WI_EXPORT wi_rsa_t * wi_rsa_init_with_public_key(wi_rsa_t *, wi_data_t *); 57 58 59 WI_EXPORT void * wi_rsa_rsa(wi_rsa_t *); 58 60 WI_EXPORT wi_data_t * wi_rsa_public_key(wi_rsa_t *); 59 61 WI_EXPORT wi_data_t * wi_rsa_private_key(wi_rsa_t *); … … 64 66 WI_EXPORT wi_data_t * wi_rsa_decrypt(wi_rsa_t *, wi_data_t *); 65 67 WI_EXPORT wi_boolean_t wi_rsa_decrypt_bytes(wi_rsa_t *, const void *, wi_uinteger_t, void **, wi_uinteger_t *); 68 69 70 WI_EXPORT wi_runtime_id_t wi_x509_runtime_id(void); 71 72 WI_EXPORT wi_x509_t * wi_x509_alloc(void); 73 WI_EXPORT wi_x509_t * wi_x509_init_with_pem_file(wi_x509_t *, wi_string_t *); 74 75 WI_EXPORT void * wi_x509_x509(wi_x509_t *); 66 76 67 77
