diff options
author | Miloslav Trmač <mitr@redhat.com> | 2010-08-06 01:51:16 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2010-08-24 20:58:31 +0200 |
commit | dfc185e27454a156863a478ac6ed3389fa4815d2 (patch) | |
tree | 874e8f40c3d99ca61ea1e2c2c097b34a86e5b10b | |
parent | 046fd8306448d3362e8f6c2ecfa9f82f71aba0fc (diff) | |
download | cryptodev-linux-dfc185e27454a156863a478ac6ed3389fa4815d2.tar.gz cryptodev-linux-dfc185e27454a156863a478ac6ed3389fa4815d2.tar.xz cryptodev-linux-dfc185e27454a156863a478ac6ed3389fa4815d2.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.c | 53 |
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) |