From: <iro...@us...> - 2004-02-16 03:47:05
|
Update of /cvsroot/perl-openssl/Crypt/OpenSSL/RSA In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31666 Modified Files: RSA.pm RSA.xs Log Message: implement constuctor completely in XS, except for the branching on key-type in new_public_key Index: RSA.pm =================================================================== RCS file: /cvsroot/perl-openssl/Crypt/OpenSSL/RSA/RSA.pm,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** RSA.pm 16 Feb 2004 02:58:59 -0000 1.31 --- RSA.pm 16 Feb 2004 03:39:19 -0000 1.32 *************** *** 94,101 **** sub new_public_key { ! my ($proto, $p_string) = @_; ! my $self = $proto->_new(); ! $self->_load_public_key($p_string); ! return $self; } --- 94,110 ---- sub new_public_key { ! my ($proto, $p_key_string) = @_; ! if ($p_key_string =~ /^-----BEGIN RSA PUBLIC KEY-----/) ! { ! return $proto->_new_public_key_pkcs1($p_key_string); ! } ! elsif ($p_key_string =~ /^-----BEGIN PUBLIC KEY-----/) ! { ! return $proto->_new_public_key_x509($p_key_string); ! } ! else ! { ! croak "unrecognized key format"; ! } } *************** *** 108,120 **** PKCS1_OAEP, but can be changed with use_xxx_padding. - =cut - - sub new_private_key - { - my $self = shift->_new(); - $self->_load_private_key(@_); - return $self; - } - =item generate_key --- 117,120 ---- *************** *** 125,137 **** PKCS1_OAEP, but can be changed with use_xxx_padding methods. - =cut - - sub generate_key - { - my $self = shift->_new(); - $self->_generate_key(@_); - return $self; - } - =item new_key_from_parameters --- 125,128 ---- *************** *** 169,180 **** } - sub _new - { - my $self = bless {}, shift; - $self->use_pkcs1_oaep_padding(); - $self->use_sha1_hash(); - return $self; - } - =back --- 160,163 ---- *************** *** 195,215 **** } - sub _load_public_key - { - my ($self, $p_key_string) = @_; - if ($p_key_string =~ /^-----BEGIN RSA PUBLIC KEY-----/) - { - $self->_load_public_pkcs1_key($p_key_string); - } - elsif ($p_key_string =~ /^-----BEGIN PUBLIC KEY-----/) - { - $self->_load_public_x509_key($p_key_string); - } - else - { - croak "unrecognized key format"; - } - } - =item get_public_key_string --- 178,181 ---- Index: RSA.xs =================================================================== RCS file: /cvsroot/perl-openssl/Crypt/OpenSSL/RSA/RSA.xs,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** RSA.xs 16 Feb 2004 02:58:59 -0000 1.35 --- RSA.xs 16 Feb 2004 03:39:19 -0000 1.36 *************** *** 200,205 **** } ! void _load_rsa_key(HV* p_rsaHv, ! SV* p_keyStringSv, RSA*(*p_loader)(BIO*, RSA**, pem_password_cb*, void*)) { --- 200,204 ---- } ! RSA* _load_rsa_key(SV* p_keyStringSv, RSA*(*p_loader)(BIO*, RSA**, pem_password_cb*, void*)) { *************** *** 210,216 **** BIO* stringBIO; - /* First; remove any old rsa structures, to avoid leakage */ - free_RSA_key(p_rsaHv); - keyString = SvPV(p_keyStringSv, keyStringLength); --- 209,212 ---- *************** *** 223,227 **** CHECK_OPEN_SSL(rsa) ! set_RSA_key(p_rsaHv, rsa); } --- 219,223 ---- CHECK_OPEN_SSL(rsa) ! return rsa; } *************** *** 232,255 **** ERR_load_crypto_strings(); ! void ! _load_private_key(rsa_HV, key_string_SV) ! HV* rsa_HV; SV* key_string_SV; CODE: ! _load_rsa_key(rsa_HV, key_string_SV, PEM_read_bio_RSAPrivateKey); ! void ! _load_public_pkcs1_key(rsa_HV, key_string_SV) ! HV* rsa_HV; SV* key_string_SV; CODE: ! _load_rsa_key(rsa_HV, key_string_SV, PEM_read_bio_RSAPublicKey); ! void ! _load_public_x509_key(rsa_HV, key_string_SV) ! HV* rsa_HV; SV* key_string_SV; CODE: ! _load_rsa_key(rsa_HV, key_string_SV, PEM_read_bio_RSA_PUBKEY); void --- 228,260 ---- ERR_load_crypto_strings(); ! SV* ! new_private_key(proto, key_string_SV) ! SV* proto; SV* key_string_SV; CODE: ! RETVAL = make_rsa_obj( ! proto, _load_rsa_key(key_string_SV, PEM_read_bio_RSAPrivateKey)); ! OUTPUT: ! RETVAL ! SV* ! _new_public_key_pkcs1(proto, key_string_SV) ! SV* proto; SV* key_string_SV; CODE: ! RETVAL = make_rsa_obj( ! proto, _load_rsa_key(key_string_SV, PEM_read_bio_RSAPublicKey)); ! OUTPUT: ! RETVAL ! SV* ! _new_public_key_x509(proto, key_string_SV) ! SV* proto; SV* key_string_SV; CODE: ! RETVAL = make_rsa_obj( ! proto, _load_rsa_key(key_string_SV, PEM_read_bio_RSA_PUBKEY)); ! OUTPUT: ! RETVAL void *************** *** 304,310 **** # ! void ! _generate_key(rsa_HV, bitsSV, ...) ! HV* rsa_HV; SV* bitsSV; PREINIT: --- 309,315 ---- # ! SV* ! generate_key(proto, bitsSV, ...) ! SV* proto; SV* bitsSV; PREINIT: *************** *** 312,316 **** unsigned long exponent; CODE: - { if (items > 3) { --- 317,320 ---- *************** *** 320,325 **** exponent = (items == 3) ? SvIV(ST(2)) : 65535; CHECK_OPEN_SSL(rsa = RSA_generate_key(SvIV(bitsSV), exponent, NULL, NULL)) ! set_RSA_key(rsa_HV, rsa); ! } SV* --- 324,332 ---- exponent = (items == 3) ? SvIV(ST(2)) : 65535; CHECK_OPEN_SSL(rsa = RSA_generate_key(SvIV(bitsSV), exponent, NULL, NULL)) ! ! RETVAL = make_rsa_obj(proto, rsa); ! OUTPUT: ! RETVAL ! SV* |