implemented and tested functionality to create sa_payload from
[strongswan.git] / Source / charon / encoding / payloads / proposal_substructure.c
index c80880d..05b375e 100644 (file)
@@ -141,7 +141,10 @@ encoding_rule_t proposal_substructure_encodings[] = {
  */
 static status_t verify(private_proposal_substructure_t *this)
 {
-       if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != PROPOSAL_SUBSTRUCTURE))
+       status_t status = SUCCESS;
+       iterator_t *iterator;
+       
+       if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != 2))
        {
                /* must be 0 or 2 */
                return FAILED;
@@ -157,9 +160,26 @@ static status_t verify(private_proposal_substructure_t *this)
                /* reserved are not supported */
                return FAILED;
        }
+       
+       iterator = this->transforms->create_iterator(this->transforms,TRUE);
+       
+       while(iterator->has_next(iterator))
+       {
+               payload_t *current_transform;
+               iterator->current(iterator,(void **)&current_transform);
+
+               status = current_transform->verify(current_transform);
+               if (status != SUCCESS)
+               {
+                       break;
+               }
+       }
+       
+       iterator->destroy(iterator);
+
 
        /* proposal number is checked in SA payload */  
-       return SUCCESS;
+       return status;
 }
 
 /**
@@ -231,6 +251,15 @@ static void add_transform_substructure (private_proposal_substructure_t *this,tr
 }
 
 /**
+ * Implementation of proposal_substructure_t.proposal_substructure_t.
+ */
+static void set_is_last_proposal (private_proposal_substructure_t *this, bool is_last)
+{
+       this->next_payload = (is_last) ? 0: PROPOSAL_TYPE_VALUE;
+}
+
+
+/**
  * Implementation of proposal_substructure_t.set_proposal_number.
  */
 static void set_proposal_number(private_proposal_substructure_t *this,u_int8_t proposal_number)
@@ -354,6 +383,22 @@ static void compute_length (private_proposal_substructure_t *this)
 }
 
 /**
+ * Implementation of proposal_substructure_t.get_transform_count.
+ */
+static size_t get_transform_count (private_proposal_substructure_t *this)
+{
+       return this->transforms->get_count(this->transforms);
+}
+
+/**
+ * Implementation of proposal_substructure_t.get_spi_size.
+ */
+static size_t get_spi_size (private_proposal_substructure_t *this)
+{
+       return  this->spi.len;
+}
+
+/**
  * Implementation of proposal_substructure_t.clone.
  */
 static private_proposal_substructure_t* clone(private_proposal_substructure_t *this)
@@ -444,8 +489,12 @@ proposal_substructure_t *proposal_substructure_create()
        this->public.set_protocol_id = (void (*) (proposal_substructure_t *,u_int8_t))set_protocol_id;
        this->public.get_protocol_id = (u_int8_t (*) (proposal_substructure_t *)) get_protocol_id;
        this->public.get_info_for_transform_type =      (status_t (*) (proposal_substructure_t *,transform_type_t,u_int16_t *, u_int16_t *))get_info_for_transform_type;
+       this->public.set_is_last_proposal = (void (*) (proposal_substructure_t *,bool)) set_is_last_proposal;
+       
        this->public.set_spi = (void (*) (proposal_substructure_t *,chunk_t))set_spi;
        this->public.get_spi = (chunk_t (*) (proposal_substructure_t *)) get_spi;
+       this->public.get_transform_count = (size_t (*) (proposal_substructure_t *)) get_transform_count;
+       this->public.get_spi_size = (size_t (*) (proposal_substructure_t *)) get_spi_size;      
        this->public.clone = (proposal_substructure_t * (*) (proposal_substructure_t *)) clone;
        this->public.destroy = (void (*) (proposal_substructure_t *)) destroy;