From cef7ba6f7024a2c3a53760be8c5fc4f937e8efb5 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Thu, 25 Feb 2016 17:27:33 -0500 Subject: RPC over loopback socket, just to work out the mechanics for serialization and dispatch. --- rpc_hash.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'rpc_hash.c') diff --git a/rpc_hash.c b/rpc_hash.c index df501cf..1bce86e 100644 --- a/rpc_hash.c +++ b/rpc_hash.c @@ -4,7 +4,7 @@ * Remote procedure call server-side hash implementation. * * Authors: Rob Austein - * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * Copyright (c) 2015-2016, NORDUnet A/S All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -143,6 +143,12 @@ static inline handle_slot_t *find_handle(const hal_hash_handle_t handle) return NULL; } +static inline free_handle(handle_slot_t *slot) +{ + /* state is a union, so this this works for hash and hmac */ + slot->state.hash = NULL; +} + /* * Translate an algorithm number to a descriptor. */ @@ -234,6 +240,7 @@ static hal_error_t initialize(const hal_client_handle_t client, { const hal_hash_descriptor_t *descriptor; handle_slot_t *slot; + hal_error_t err; if (hash == NULL) return HAL_ERROR_BAD_ARGUMENTS; @@ -241,16 +248,20 @@ static hal_error_t initialize(const hal_client_handle_t client, if ((descriptor = alg_to_descriptor(alg)) == NULL) return HAL_ERROR_BAD_ARGUMENTS; - if ((slot = alloc_handle(key != NULL)) == NULL) + if ((slot = alloc_handle(key_len != 0)) == NULL) return HAL_ERROR_ALLOCATION_FAILURE; slot->client_handle = client; slot->session_handle = session; + *hash = slot->hash_handle; - if (key == NULL) - return hal_hash_initialize(NULL, descriptor, &slot->state.hash, NULL, 0); + if (key_len == 0) + err = hal_hash_initialize(NULL, descriptor, &slot->state.hash, NULL, 0); else - return hal_hmac_initialize(NULL, descriptor, &slot->state.hmac, NULL, 0, key, key_len); + err = hal_hmac_initialize(NULL, descriptor, &slot->state.hmac, NULL, 0, key, key_len); + if (err != HAL_OK) + free_handle(slot); + return err; } static hal_error_t update(const hal_hash_handle_t handle, @@ -286,6 +297,7 @@ static hal_error_t finalize(const hal_hash_handle_t handle, hal_hmac_cleanup(&slot->state.hmac); } + free_handle(slot); return err; } -- cgit v1.2.3