Richard,
I understand very well the benefit of using only one function to do the same work, but they are already 2 function that does the same for private keys and for consistency i think i had to submit 2 function to do the same job for public keys.
Of course the best way is to have only too function to do the job (one for public and one for private keys) but i just can't decide myself to break compatibility.
So i submit my two little functions. Sorry this is not a patch.
Regards, Eric
At 16:59 05/11/2003, Richard Burton wrote:
Eric,
Might I suggest that if you submit a patch for this, you add just one function and check for a "file://" prefix to determine if the user want to work with a file or variable? This is the way certificates are handled at present, and I used this method for my patch to try and be consistent with it.
I'm a big fan of consistency, but I know others' views differ. I guess it's over to Wez for guidence, since it's his extension?
Richard.
From: Eric COLINET <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
CC: <[EMAIL PROTECTED]>
Subject: Re: [PHP-DEV] [PATCH] openssl_pkcs7_encrypt to/from variable or file
Date: Wed, 05 Nov 2003 12:57:20 +0100
Hi !
In the same series ..
I have no patch to provide but i've written two functions related to php_openssl:
openssl_pubkey_export
openssl_pubkey_export_to_file
That simply allow the export of public keys that seems to be not possible before.
I there is no special reason for that i can submit them (they are small modification of openssl_pkey_export & openssl_pkey_export_to_file)
Eric
_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection http://www.msn.co.uk/specials/btbroadband
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
/* {{{ proto bool openssl_pkey_public_export_to_file(mixed key, string outfilename) Gets an exportable representation of a public key into a file */ PHP_FUNCTION(openssl_pkey_public_export_to_file) { struct php_x509_request req; zval * zpkey; char * filename = NULL; long filename_len = 0; long key_resource = -1; EVP_PKEY * key; BIO * bio_out = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &zpkey, &filename, &filename_len ) == FAILURE) return;
RETVAL_FALSE; key = php_openssl_evp_from_zval(&zpkey, 1, NULL, 0, &key_resource TSRMLS_CC); if (key == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot get key from parameter 1"); RETURN_FALSE; } if (php_openssl_safe_mode_chk(filename TSRMLS_CC)) { RETURN_FALSE; } PHP_SSL_REQ_INIT(&req); bio_out = BIO_new_file(filename, "w"); if (PEM_write_bio_PUBKEY(bio_out, key)) { /* Success! */ RETVAL_TRUE; } PHP_SSL_REQ_DISPOSE(&req); if (key_resource == -1 && key) { EVP_PKEY_free(key); } if (bio_out) BIO_free(bio_out); } /* }}} */ /* {{{ proto bool openssl_pkey_public_export(mixed key, &mixed out) Gets an exportable representation of a public key into a string */ PHP_FUNCTION(openssl_pkey_public_export) { struct php_x509_request req; zval * zpkey, *out; long key_resource = -1; EVP_PKEY * key; BIO * bio_out = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &zpkey, &out) == FAILURE) return; RETVAL_FALSE; key = php_openssl_evp_from_zval(&zpkey, 1, NULL, 0, &key_resource TSRMLS_CC); if (key == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot get key from parameter 1"); RETURN_FALSE; } PHP_SSL_REQ_INIT(&req); bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_PUBKEY(bio_out, key)) { /* Success! * If returning the output as a string, do so now */ char * bio_mem_ptr; long bio_mem_len; RETVAL_TRUE; bio_mem_len = BIO_get_mem_data(bio_out, &bio_mem_ptr); ZVAL_STRINGL(out, bio_mem_ptr, bio_mem_len, 1); } PHP_SSL_REQ_DISPOSE(&req); if (key_resource == -1 && key) { EVP_PKEY_free(key); } if (bio_out) BIO_free(bio_out); } /* }}} */
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php