mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-27 13:21:11 +03:00
Replace some strcmp with switch to make it a bit faster.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@545 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -586,7 +586,7 @@ PRIVATE_KEY *privatekey_make_rsa(SSH_SESSION *session, BUFFER *buffer,
|
|||||||
PRIVATE_KEY *privatekey_from_string(SSH_SESSION *session, STRING *privkey_s);
|
PRIVATE_KEY *privatekey_from_string(SSH_SESSION *session, STRING *privkey_s);
|
||||||
|
|
||||||
PUBLIC_KEY *publickey_make_dss(SSH_SESSION *session, BUFFER *buffer);
|
PUBLIC_KEY *publickey_make_dss(SSH_SESSION *session, BUFFER *buffer);
|
||||||
PUBLIC_KEY *publickey_make_rsa(SSH_SESSION *session, BUFFER *buffer, const char *type);
|
PUBLIC_KEY *publickey_make_rsa(SSH_SESSION *session, BUFFER *buffer, int type);
|
||||||
PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s);
|
PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s);
|
||||||
SIGNATURE *signature_from_string(SSH_SESSION *session, STRING *signature,PUBLIC_KEY *pubkey,int needed_type);
|
SIGNATURE *signature_from_string(SSH_SESSION *session, STRING *signature,PUBLIC_KEY *pubkey,int needed_type);
|
||||||
void signature_free(SIGNATURE *sign);
|
void signature_free(SIGNATURE *sign);
|
||||||
|
|||||||
@@ -37,15 +37,16 @@
|
|||||||
/* Public key decoding functions */
|
/* Public key decoding functions */
|
||||||
|
|
||||||
const char *ssh_type_to_char(int type) {
|
const char *ssh_type_to_char(int type) {
|
||||||
switch(type){
|
switch (type) {
|
||||||
case TYPE_DSS:
|
case TYPE_DSS:
|
||||||
return "ssh-dss";
|
return "ssh-dss";
|
||||||
case TYPE_RSA:
|
case TYPE_RSA:
|
||||||
case TYPE_RSA1:
|
return "ssh-rsa";
|
||||||
return "ssh-rsa";
|
case TYPE_RSA1:
|
||||||
default:
|
return "ssh-rsa1";
|
||||||
return NULL;
|
default:
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_type_from_name(const char *name) {
|
int ssh_type_from_name(const char *name) {
|
||||||
@@ -80,7 +81,7 @@ PUBLIC_KEY *publickey_make_dss(SSH_SESSION *session, BUFFER *buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
key->type = TYPE_DSS;
|
key->type = TYPE_DSS;
|
||||||
key->type_c = ssh_type_from_name(key->type);
|
key->type_c = ssh_type_to_char(key->type);
|
||||||
|
|
||||||
p = buffer_get_ssh_string(buffer);
|
p = buffer_get_ssh_string(buffer);
|
||||||
q = buffer_get_ssh_string(buffer);
|
q = buffer_get_ssh_string(buffer);
|
||||||
@@ -153,7 +154,7 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC_KEY *publickey_make_rsa(SSH_SESSION *session, BUFFER *buffer,
|
PUBLIC_KEY *publickey_make_rsa(SSH_SESSION *session, BUFFER *buffer,
|
||||||
const char *type) {
|
int type) {
|
||||||
STRING *e = NULL;
|
STRING *e = NULL;
|
||||||
STRING *n = NULL;
|
STRING *n = NULL;
|
||||||
PUBLIC_KEY *key = NULL;
|
PUBLIC_KEY *key = NULL;
|
||||||
@@ -164,13 +165,9 @@ PUBLIC_KEY *publickey_make_rsa(SSH_SESSION *session, BUFFER *buffer,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(type, "ssh-rsa") == 0) {
|
key->type = type;
|
||||||
key->type = TYPE_RSA;
|
|
||||||
} else {
|
|
||||||
key->type = TYPE_RSA1;
|
|
||||||
}
|
|
||||||
|
|
||||||
key->type_c = ssh_type_to_char(key->type);
|
key->type_c = ssh_type_to_char(key->type);
|
||||||
|
|
||||||
e = buffer_get_ssh_string(buffer);
|
e = buffer_get_ssh_string(buffer);
|
||||||
n = buffer_get_ssh_string(buffer);
|
n = buffer_get_ssh_string(buffer);
|
||||||
|
|
||||||
@@ -253,7 +250,8 @@ void publickey_free(PUBLIC_KEY *key) {
|
|||||||
PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s) {
|
PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s) {
|
||||||
BUFFER *tmpbuf = NULL;
|
BUFFER *tmpbuf = NULL;
|
||||||
STRING *type_s = NULL;
|
STRING *type_s = NULL;
|
||||||
char *type = NULL;
|
char *type_c = NULL;
|
||||||
|
int type;
|
||||||
|
|
||||||
tmpbuf = buffer_new();
|
tmpbuf = buffer_new();
|
||||||
if (tmpbuf == NULL) {
|
if (tmpbuf == NULL) {
|
||||||
@@ -270,30 +268,28 @@ PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
type = string_to_char(type_s);
|
type_c = string_to_char(type_s);
|
||||||
string_free(type_s);
|
string_free(type_s);
|
||||||
|
if (type_c == NULL) {
|
||||||
if (type == NULL) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(type, "ssh-dss") == 0) {
|
type = ssh_type_from_name(type_c);
|
||||||
SAFE_FREE(type);
|
SAFE_FREE(type_c);
|
||||||
return publickey_make_dss(session, tmpbuf);
|
|
||||||
}
|
switch (type) {
|
||||||
if(strcmp(type,"ssh-rsa") == 0) {
|
case TYPE_DSS:
|
||||||
SAFE_FREE(type);
|
return publickey_make_dss(session, tmpbuf);
|
||||||
return publickey_make_rsa(session, tmpbuf,"ssh-rsa");
|
case TYPE_RSA:
|
||||||
}
|
case TYPE_RSA1:
|
||||||
if (strcmp(type,"ssh-rsa1") == 0) {
|
return publickey_make_rsa(session, tmpbuf, type);
|
||||||
SAFE_FREE(type);
|
|
||||||
return publickey_make_rsa(session, tmpbuf,"ssh-rsa1");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ssh_set_error(session, SSH_FATAL, "Unknown public key protocol %s", type);
|
ssh_set_error(session, SSH_FATAL, "Unknown public key protocol %s",
|
||||||
|
ssh_type_to_char(type));
|
||||||
|
|
||||||
error:
|
error:
|
||||||
buffer_free(tmpbuf);
|
buffer_free(tmpbuf);
|
||||||
SAFE_FREE(type);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user