Implemented encoding of additional IKEv1 proposal attributes
[strongswan.git] / src / libcharon / encoding / payloads / transform_attribute.c
index e928dcd..7e8a9c7 100644 (file)
@@ -134,12 +134,17 @@ METHOD(payload_t, verify, status_t,
        return SUCCESS;
 }
 
-METHOD(payload_t, get_encoding_rules, void,
-       private_transform_attribute_t *this, encoding_rule_t **rules,
-       size_t *rule_count)
+METHOD(payload_t, get_encoding_rules, int,
+       private_transform_attribute_t *this, encoding_rule_t **rules)
 {
        *rules = encodings;
-       *rule_count = countof(encodings);
+       return countof(encodings);
+}
+
+METHOD(payload_t, get_header_length, int,
+       private_transform_attribute_t *this)
+{
+       return 0;
 }
 
 METHOD(payload_t, get_type, payload_type_t,
@@ -259,6 +264,7 @@ transform_attribute_t *transform_attribute_create(payload_type_t type)
                        .payload_interface = {
                                .verify = _verify,
                                .get_encoding_rules = _get_encoding_rules,
+                               .get_header_length = _get_header_length,
                                .get_length = _get_length,
                                .get_next_type = _get_next_type,
                                .set_next_type = _set_next_type,
@@ -283,13 +289,29 @@ transform_attribute_t *transform_attribute_create(payload_type_t type)
 /*
  * Described in header.
  */
-transform_attribute_t *transform_attribute_create_key_length(u_int16_t key_length)
+transform_attribute_t *transform_attribute_create_value(payload_type_t type,
+                                                       transform_attribute_type_t kind, u_int64_t value)
 {
        transform_attribute_t *attribute;
 
-       attribute = transform_attribute_create(TRANSFORM_ATTRIBUTE);
-       attribute->set_attribute_type(attribute, TATTR_IKEV2_KEY_LENGTH);
-       attribute->set_value(attribute, key_length);
+       attribute = transform_attribute_create(type);
+       attribute->set_attribute_type(attribute, kind);
+
+       if (value <= UINT16_MAX)
+       {
+               attribute->set_value(attribute, value);
+       }
+       else if (value <= UINT32_MAX)
+       {
+               u_int32_t val32;
 
+               val32 = htonl(value);
+               attribute->set_value_chunk(attribute, chunk_from_thing(val32));
+       }
+       else
+       {
+               value = htobe64(value);
+               attribute->set_value_chunk(attribute, chunk_from_thing(value));
+       }
        return attribute;
 }