Allow NULL value_len in yaca_context_get_property(). Fix documentation. 01/77701/4
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 30 Jun 2016 13:10:17 +0000 (15:10 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 6 Jul 2016 10:27:06 +0000 (03:27 -0700)
In cases where a property is a single object of a known type theres no point in
passing value_len to yaca_context_get_property().

The documentation related to property getting/setting has been updated.

Change-Id: Idf908e87b87b5fe5239f651fe8546a7bd5a89850

api/yaca/yaca_crypto.h
api/yaca/yaca_types.h
src/encrypt.c
src/sign.c

index baf0315..20cae17 100644 (file)
@@ -190,6 +190,9 @@ int yaca_randomize_bytes(char *data, size_t data_len);
  * @brief  Sets the non-standard context properties. Can only be called on an
  *         initialized context.
  *
+ * @remarks  The @a value has to be of type appropriate for given property. See #yaca_property_e
+ *           for details on corresponding types.
+ *
  * @since_tizen 3.0
  *
  * @param[in,out] ctx        Previously initialized crypto context
@@ -219,6 +222,11 @@ int yaca_context_set_property(yaca_context_h ctx,
  *
  * @remarks  The @a value should be freed using yaca_free()
  *
+ * @remarks  The @a value has to be of type appropriate for given property. See #yaca_property_e
+ *           for details on corresponding types.
+ *
+ * @remarks  @a value_len can be NULL if returned @a value is a single object (i.e. not an array/buffer)
+ *
  * @param[in]  ctx        Previously initialized crypto context
  * @param[in]  property   Property to be read
  * @param[out] value      Copy of the property value
index 2d5edc9..4508c8d 100644 (file)
@@ -385,23 +385,25 @@ typedef enum {
  * @brief Enumeration of YACA non-standard properties for algorithms.
  *
  * @since_tizen 3.0
+ *
+ * @see #yaca_padding_e
  */
 typedef enum {
-       /** Padding */
+       /** Padding. Property type is #yaca_padding_e. */
        YACA_PROPERTY_PADDING,
 
-       /** GCM Additional Authentication Data */
+       /** GCM Additional Authentication Data. Property type is a buffer (e.g. char*) */
        YACA_PROPERTY_GCM_AAD,
-       /** GCM Tag bits */
+       /** GCM Tag. Property type is a buffer (e.g. char*) */
        YACA_PROPERTY_GCM_TAG,
-       /** GCM Tag length */
+       /** GCM Tag length. Property type is size_t. */
        YACA_PROPERTY_GCM_TAG_LEN,
 
-       /** CCM Additional Authentication Data */
+       /** CCM Additional Authentication Data. Property type is a buffer (e.g. char*) */
        YACA_PROPERTY_CCM_AAD,
-       /** CCM Tag bits */
+       /** CCM Tag. Property type is a buffer (e.g. char*) */
        YACA_PROPERTY_CCM_TAG,
-       /** CCM Tag length */
+       /** CCM Tag length. Property type is size_t. */
        YACA_PROPERTY_CCM_TAG_LEN
 } yaca_property_e;
 
index 5942e2e..b248896 100644 (file)
@@ -168,13 +168,13 @@ int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property,
 {
        struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
 
-       if (c == NULL || value == NULL || value_len == NULL)
+       if (c == NULL || value == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
        assert(c->cipher_ctx != NULL);
 
        switch (property) {
        case YACA_PROPERTY_GCM_TAG:
-               if (c->tag_len == 0)
+               if (c->tag_len == 0 || value_len == 0)
                        return YACA_ERROR_INVALID_PARAMETER;
 
                if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
@@ -186,7 +186,7 @@ int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property,
                *value_len = c->tag_len;
                break;
        case YACA_PROPERTY_CCM_TAG:
-               if (c->tag_len == 0)
+               if (c->tag_len == 0 || value_len == 0)
                        return YACA_ERROR_INVALID_PARAMETER;
 
                if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
index 5dd261c..acb0392 100644 (file)
@@ -179,7 +179,7 @@ int get_sign_param(const yaca_context_h ctx,
        int pad;
        yaca_padding_e padding;
 
-       if (c == NULL || value == NULL || value_len == NULL)
+       if (c == NULL || value == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
        assert(c->mdctx != NULL);
@@ -230,7 +230,8 @@ int get_sign_param(const yaca_context_h ctx,
                return ret;
 
        memcpy(*value, &padding, sizeof(yaca_padding_e));
-       *value_len = sizeof(yaca_padding_e);
+       if (value_len != NULL)
+               *value_len = sizeof(yaca_padding_e);
 
        return YACA_ERROR_NONE;
 }