aboutsummaryrefslogtreecommitdiff
path: root/libssh/keys.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-18 11:18:35 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-18 11:18:35 +0000
commitff73826b45c7ea08d5cb8aa9478f822dc58c8c12 (patch)
tree4e891a047dadeed19639e0e658436a6bbfe3a677 /libssh/keys.c
parent95cd02c0009d62e7ee5ac306a45c48a7e52c262b (diff)
downloadlibssh-ff73826b45c7ea08d5cb8aa9478f822dc58c8c12.tar.gz
libssh-ff73826b45c7ea08d5cb8aa9478f822dc58c8c12.tar.xz
libssh-ff73826b45c7ea08d5cb8aa9478f822dc58c8c12.zip
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
Diffstat (limited to 'libssh/keys.c')
-rw-r--r--libssh/keys.c64
1 files changed, 30 insertions, 34 deletions
diff --git a/libssh/keys.c b/libssh/keys.c
index f53f2fdf..633585a9 100644
--- a/libssh/keys.c
+++ b/libssh/keys.c
@@ -37,15 +37,16 @@
/* Public key decoding functions */
const char *ssh_type_to_char(int type) {
- switch(type){
- case TYPE_DSS:
- return "ssh-dss";
- case TYPE_RSA:
- case TYPE_RSA1:
- return "ssh-rsa";
- default:
- return NULL;
- }
+ switch (type) {
+ case TYPE_DSS:
+ return "ssh-dss";
+ case TYPE_RSA:
+ return "ssh-rsa";
+ case TYPE_RSA1:
+ return "ssh-rsa1";
+ default:
+ return NULL;
+ }
}
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_c = ssh_type_from_name(key->type);
+ key->type_c = ssh_type_to_char(key->type);
p = 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,
- const char *type) {
+ int type) {
STRING *e = NULL;
STRING *n = NULL;
PUBLIC_KEY *key = NULL;
@@ -164,13 +165,9 @@ PUBLIC_KEY *publickey_make_rsa(SSH_SESSION *session, BUFFER *buffer,
return NULL;
}
- if (strcmp(type, "ssh-rsa") == 0) {
- key->type = TYPE_RSA;
- } else {
- key->type = TYPE_RSA1;
- }
-
+ key->type = type;
key->type_c = ssh_type_to_char(key->type);
+
e = 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) {
BUFFER *tmpbuf = NULL;
STRING *type_s = NULL;
- char *type = NULL;
+ char *type_c = NULL;
+ int type;
tmpbuf = buffer_new();
if (tmpbuf == NULL) {
@@ -270,30 +268,28 @@ PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s) {
goto error;
}
- type = string_to_char(type_s);
+ type_c = string_to_char(type_s);
string_free(type_s);
-
- if (type == NULL) {
+ if (type_c == NULL) {
goto error;
}
- if(strcmp(type, "ssh-dss") == 0) {
- SAFE_FREE(type);
- return publickey_make_dss(session, tmpbuf);
- }
- if(strcmp(type,"ssh-rsa") == 0) {
- SAFE_FREE(type);
- return publickey_make_rsa(session, tmpbuf,"ssh-rsa");
- }
- if (strcmp(type,"ssh-rsa1") == 0) {
- SAFE_FREE(type);
- return publickey_make_rsa(session, tmpbuf,"ssh-rsa1");
+ type = ssh_type_from_name(type_c);
+ SAFE_FREE(type_c);
+
+ switch (type) {
+ case TYPE_DSS:
+ return publickey_make_dss(session, tmpbuf);
+ case TYPE_RSA:
+ case TYPE_RSA1:
+ return publickey_make_rsa(session, tmpbuf, type);
}
- 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:
buffer_free(tmpbuf);
- SAFE_FREE(type);
return NULL;
}