summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-08-06 01:51:16 +0200
committerMiloslav Trmač <mitr@redhat.com>2010-08-23 20:01:59 +0200
commitc61ec8d5ec0e30b60f04fbce411082ae8019051b (patch)
treef0db4846d37409b52787991491e6a0288fb1b624
parent3bbecb0f648f3f831523e23f02a81e3e2cd5feac (diff)
downloadcryptodev-linux-c61ec8d5ec0e30b60f04fbce411082ae8019051b.tar.gz
cryptodev-linux-c61ec8d5ec0e30b60f04fbce411082ae8019051b.tar.xz
cryptodev-linux-c61ec8d5ec0e30b60f04fbce411082ae8019051b.zip
Add helper function ncr_key_get_info
This avoids code duplication in the various ncr_key_get_* functions.
-rw-r--r--userspace/ncrypto_key.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/userspace/ncrypto_key.c b/userspace/ncrypto_key.c
index 6d9548d..e424c87 100644
--- a/userspace/ncrypto_key.c
+++ b/userspace/ncrypto_key.c
@@ -101,51 +101,45 @@ ncr_key_derive(ncr_key_t newkey, unsigned int keyflags, ncr_key_t key, ncr_key_p
return 0;
}
-int
-ncr_key_get_flags(ncr_key_t key)
+static int
+ncr_key_get_info(struct ncr_key_info_st *dest, ncr_key_t key)
{
- struct ncr_key_info_st io;
- memset(&io, 0, sizeof(io));
-
if (key == NCR_KEY_INVALID) {
errno = EINVAL;
return -1;
}
- io.key = key;
+ memset(dest, 0, sizeof(*dest));
+ dest->key = key;
if (__ncr_file_descriptor < 0) {
errno = EBADF;
return -1;
}
- if (ioctl(__ncr_file_descriptor, NCRIO_KEY_GET_INFO, &io) < 0)
+ if (ioctl(__ncr_file_descriptor, NCRIO_KEY_GET_INFO, dest) < 0)
return -1;
- return io.flags;
+ return 0;
}
-ncr_key_type_t
-ncr_key_get_type(ncr_key_t key)
+int
+ncr_key_get_flags(ncr_key_t key)
{
struct ncr_key_info_st io;
- memset(&io, 0, sizeof(io));
- if (key == NCR_KEY_INVALID) {
- errno = EINVAL;
+ if (ncr_key_get_info(&io, key) < 0)
return -1;
- }
-
- io.key = key;
+ return io.flags;
+}
- if (__ncr_file_descriptor < 0) {
- errno = EBADF;
- return -1;
- }
+ncr_key_type_t
+ncr_key_get_type(ncr_key_t key)
+{
+ struct ncr_key_info_st io;
- if (ioctl(__ncr_file_descriptor, NCRIO_KEY_GET_INFO, &io) < 0)
+ if (ncr_key_get_info(&io, key) < 0)
return -1;
-
return io.type;
}
@@ -153,21 +147,8 @@ int
ncr_key_get_id(ncr_key_t key, void *id, size_t *id_size)
{
struct ncr_key_info_st io;
- memset(&io, 0, sizeof(io));
-
- if (key == NCR_KEY_INVALID) {
- errno = EINVAL;
- return -1;
- }
-
- io.key = key;
-
- if (__ncr_file_descriptor < 0) {
- errno = EBADF;
- return -1;
- }
- if (ioctl(__ncr_file_descriptor, NCRIO_KEY_GET_INFO, &io) < 0)
+ if (ncr_key_get_info(&io, key) < 0)
return -1;
if (io.key_id_size < *id_size)