implemented and tested functionality to create sa_payload from
[strongswan.git] / Source / charon / encoding / payloads / transform_substructure.c
index 4e3655b..99af36c 100644 (file)
@@ -148,7 +148,10 @@ encoding_rule_t transform_substructure_encodings[] = {
  */
 static status_t verify(private_transform_substructure_t *this)
 {
-       if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != TRANSFORM_SUBSTRUCTURE))
+       status_t status = SUCCESS;
+       iterator_t *iterator;
+       
+       if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != 3))
        {
                /* must be 0 or 3 */
                return FAILED;
@@ -218,9 +221,25 @@ static status_t verify(private_transform_substructure_t *this)
                        return FAILED;
                }
        }
+       iterator = this->attributes->create_iterator(this->attributes,TRUE);
+       
+       while(iterator->has_next(iterator))
+       {
+               payload_t *current_attributes;
+               iterator->current(iterator,(void **)&current_attributes);
+
+               status = current_attributes->verify(current_attributes);
+               if (status != SUCCESS)
+               {
+                       break;
+               }
+       }
+       
+       iterator->destroy(iterator);
+
 
        /* proposal number is checked in SA payload */  
-       return SUCCESS;
+       return status;
 }
 
 /**
@@ -429,7 +448,7 @@ static void destroy(private_transform_substructure_t *this)
 }
 
 /*
- * Described in header
+ * Described in header.
  */
 transform_substructure_t *transform_substructure_create()
 {
@@ -469,3 +488,31 @@ transform_substructure_t *transform_substructure_create()
        
        return (&(this->public));
 }
+
+/*
+ * Described in header
+ */
+transform_substructure_t *transform_substructure_create_type(transform_type_t transform_type, u_int16_t transform_id, u_int16_t key_length)
+{
+       transform_substructure_t *transform = transform_substructure_create();
+       
+       transform->set_transform_type(transform,transform_type);
+       transform->set_transform_id(transform,transform_id);
+       
+       switch (transform_type)
+       {
+               case ENCRYPTION_ALGORITHM:
+               case PSEUDO_RANDOM_FUNCTION:
+               case INTEGRITY_ALGORITHM:
+               {
+                       transform_attribute_t *attribute = transform_attribute_create_key_length(key_length);
+                       transform->add_transform_attribute(transform,attribute);
+                       break;
+               }
+               default:
+               {
+                       /* no keylength attribute is created */
+               }
+       }       
+       return transform;
+}