Extend attribute setting routines to support non-string types.
[openssl.git] / crypto / asn1 / a_type.c
index 6a1e5a7a5ac54b5dc812e4e093d951a96d24f6d0..52523d210afa429e03b7405f709138412d2df197 100644 (file)
@@ -77,9 +77,36 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
                ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
                }
        a->type=type;
-       a->value.ptr=value;
+       if (type == V_ASN1_BOOLEAN)
+               a->value.boolean = value ? 0xff : 0;
+       else
+               a->value.ptr=value;
        }
 
+int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
+       {
+       if (!value || (type == V_ASN1_BOOLEAN))
+               {
+               ASN1_TYPE_set(a, type, (void *)value);
+               }
+       else if (type == V_ASN1_OBJECT)
+               {
+               ASN1_OBJECT *odup;
+               odup = OBJ_dup(value);
+               if (!odup)
+                       return 0;
+               ASN1_TYPE_set(a, type, odup);
+               }
+       else
+               {
+               ASN1_STRING *sdup;
+               sdup = ASN1_STRING_dup(sdup);
+               if (!sdup)
+                       return 0;
+               ASN1_TYPE_set(a, type, sdup);
+               }
+       return 1;
+       }
 
 IMPLEMENT_STACK_OF(ASN1_TYPE)
 IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)