diff options
| author | Artyom Poptsov <poptsov.artyom@gmail.com> | 2014-06-01 01:02:47 +0400 |
|---|---|---|
| committer | Artyom Poptsov <poptsov.artyom@gmail.com> | 2014-06-01 01:02:47 +0400 |
| commit | 3add773c07d58238834d07b2b266bda56eac193d (patch) | |
| tree | 480245d60ca8e0f5b2cf53ef127abef16b275dd6 | |
| parent | ssh/key-type.c (_scm_to_ssh_key_type): Fix return type (diff) | |
| download | guile-ssh-3add773c07d58238834d07b2b266bda56eac193d.tar.gz | |
ssh/key.scm (string->public-key): New procedure
* ssh/key.scm (string->public-key): New procedure.
* ssh/key-func.c (guile_ssh_string_to_public_key): New procedure.
* ssh/key-func.h: Likewise.
* doc/api-keys.texi (Keys): Add description of
`string->public-key'.
| -rw-r--r-- | ChangeLog | 6 | ||||
| -rw-r--r-- | doc/api-keys.texi | 8 | ||||
| -rw-r--r-- | ssh/key-func.c | 41 | ||||
| -rw-r--r-- | ssh/key-func.h | 1 | ||||
| -rw-r--r-- | ssh/key.scm | 1 |
5 files changed, 57 insertions, 0 deletions
@@ -1,5 +1,11 @@ 2014-06-01 Artyom Poptsov <poptsov.artyom@gmail.com> + * ssh/key.scm (string->public-key): New procedure. + * ssh/key-func.c (guile_ssh_string_to_public_key): New procedure. + * ssh/key-func.h: Likewise. + * doc/api-keys.texi (Keys): Add description of + `string->public-key'. + * ssh/key-type.c (scm_from_ssh_key_type): Rename to `_ssh_key_type_to_scm'. Make it public. (_scm_to_ssh_key_type): New procedure. diff --git a/doc/api-keys.texi b/doc/api-keys.texi index c3e1580..99ba8a8 100644 --- a/doc/api-keys.texi +++ b/doc/api-keys.texi @@ -31,6 +31,14 @@ otherwise. Convert @var{public-key} to a string. @end deffn +@deffn {Scheme Procedure} string->public-key string type +Convert a public key of @var{type} represented as Base64 @var{string} +to a Guile-SSH key. Throw @code{guile-ssh-error} on error. + +The @var{type} must be one of the following symbols: @code{dss}, +@code{rsa}, @code{rsa1}, @code{ecdsa} +@end deffn + @deffn {Scheme Procedure} private-key-from-file session file Read private key from a @var{file}. If the the key is encrypted the user will be asked for passphrase to decrypt the key. diff --git a/ssh/key-func.c b/ssh/key-func.c index bb95c2d..7a127f0 100644 --- a/ssh/key-func.c +++ b/ssh/key-func.c @@ -44,6 +44,47 @@ SCM_DEFINE (guile_ssh_public_key_to_string, "public-key->string", 1, 0, 0, } #undef FUNC_NAME +SCM_DEFINE (guile_ssh_string_to_public_key, "string->public-key", 2, 0, 0, + (SCM base64_str, SCM type), + "Convert Base64 string to a public key. Return new public key.\n" + "Throw `guile-ssh-error' on error.") +#define FUNC_NAME s_guile_ssh_string_to_public_key +{ + struct key_data *kd = NULL; + char *c_base64_str = NULL; + struct symbol_mapping *key_type = NULL; + int res; + SCM key_smob; + + SCM_ASSERT (scm_is_string (base64_str), base64_str, SCM_ARG1, FUNC_NAME); + SCM_ASSERT (scm_is_symbol (type), type, SCM_ARG2, FUNC_NAME); + + scm_dynwind_begin (0); + + kd = scm_gc_malloc (sizeof (struct key_data), "ssh key"); + + c_base64_str = scm_to_locale_string (base64_str); + scm_dynwind_free (c_base64_str); + + key_type = _scm_to_ssh_key_type (type); + if (! key_type) + guile_ssh_error1 (FUNC_NAME, "Wrong key type", type); + + res = ssh_pki_import_pubkey_base64 (c_base64_str, + key_type->value, + &kd->ssh_key); + if (res != SSH_OK) + { + const char *msg = "Could not convert the given string to a public key"; + guile_ssh_error1 (FUNC_NAME, msg, scm_list_2 (base64_str, type)); + } + + SCM_NEWSMOB (key_smob, key_tag, kd); + + return key_smob; +} +#undef FUNC_NAME + SCM_DEFINE (guile_ssh_private_key_from_file, "private-key-from-file", 2, 0, 0, (SCM session, SCM filename), "Read private key from a file FILENAME. If the the key is " diff --git a/ssh/key-func.h b/ssh/key-func.h index 557fe34..219051c 100644 --- a/ssh/key-func.h +++ b/ssh/key-func.h @@ -24,6 +24,7 @@ public_key_to_ssh_string (const struct key_data* public_key_data); /* Guile SSH API */ +extern SCM guile_ssh_string_to_public_key (SCM arg1, SCM arg2); extern SCM guile_ssh_public_key_to_string (SCM arg1); extern SCM guile_ssh_private_key_from_file (SCM arg1, SCM arg2); extern SCM guile_ssh_public_key_from_file (SCM arg1, SCM arg2); diff --git a/ssh/key.scm b/ssh/key.scm index 6313cdd..49e3d3f 100644 --- a/ssh/key.scm +++ b/ssh/key.scm @@ -46,6 +46,7 @@ private-key? get-key-type public-key->string + string->public-key public-key-from-file private-key->public-key private-key-from-file |
