implemented and tested functionality to create sa_payload from
[strongswan.git] / Source / charon / encoding / payloads / proposal_substructure.h
index 1da42d1..a2015fb 100644 (file)
@@ -1,9 +1,7 @@
 /**
  * @file proposal_substructure.h
  * 
- * @brief Declaration of the class proposal_substructure_t. 
- * 
- * An object of this type represents an IKEv2 PROPOSAL Substructure and contains transforms.
+ * @brief Interface of proposal_substructure_t.
  * 
  */
 
 #include <utils/linked_list.h>
 
 /**
+ * IKEv1 Value for a proposal payload.
+ * 
+ * @ingroup payloads
+ */
+#define PROPOSAL_TYPE_VALUE 2
+
+/**
  * Length of the proposal substructure header
- * (without spi)
+ * (without spi).
+ * 
+ * @ingroup payloads
  */
 #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8
 
 
+typedef enum protocol_id_t protocol_id_t;
+
 /**
- * Protocol ID of a proposal
+ * Protocol ID of a proposal.
+ * 
+ * @ingroup payloads
  */
-typedef enum protocol_id_e protocol_id_t;
-
-enum protocol_id_e {
+enum protocol_id_t {
        UNDEFINED_PROTOCOL_ID = 201,
        IKE = 1,
        AH = 2,
        ESP = 3,
 };         
 
+typedef struct proposal_substructure_t proposal_substructure_t;
+
 /**
- * Object representing an IKEv2- PROPOSAL SUBSTRUCTURE
+ * Object representing an IKEv2-PROPOSAL SUBSTRUCTURE.
  * 
  * The PROPOSAL SUBSTRUCTURE format is described in RFC section 3.3.1.
  * 
+ * @ingroup payloads
  */
-typedef struct proposal_substructure_s proposal_substructure_t;
-
-struct proposal_substructure_s {
+struct proposal_substructure_t {
        /**
-        * implements payload_t interface
+        * The payload_t interface.
         */
        payload_t payload_interface;
 
@@ -71,13 +81,10 @@ struct proposal_substructure_s {
         *                      get_size to make sure the length and number values are ok.
         *
         * @param this                  calling proposal_substructure_t object
-        * @param iterator              the created iterator is stored at the pointed pointer
         * @param[in] forward   iterator direction (TRUE: front to end)
-        * @return              
-        *                                              - SUCCESS or
-        *                                              - OUT_OF_RES if iterator could not be created
+        * @return                              created iterator_t object
         */
-       status_t (*create_transform_substructure_iterator) (proposal_substructure_t *this,linked_list_iterator_t **iterator, bool forward);
+       iterator_t * (*create_transform_substructure_iterator) (proposal_substructure_t *this, bool forward);
        
        /**
         * @brief Adds a transform_substructure_t object to this object.
@@ -87,19 +94,16 @@ struct proposal_substructure_s {
         *
         * @param this          calling proposal_substructure_t object
         * @param transform transform_substructure_t object to add
-        * @return                      - SUCCESS if succeeded
-        *                                      - FAILED otherwise
         */
-       status_t (*add_transform_substructure) (proposal_substructure_t *this,transform_substructure_t *transform);
+       void (*add_transform_substructure) (proposal_substructure_t *this,transform_substructure_t *transform);
        
        /**
         * @brief Sets the proposal number of current proposal.
         *
         * @param this          calling proposal_substructure_t object
         * @param id                    proposal number to set
-        * @return                      - SUCCESS
         */
-       status_t (*set_proposal_number) (proposal_substructure_t *this,u_int8_t proposal_number);
+       void (*set_proposal_number) (proposal_substructure_t *this,u_int8_t proposal_number);
        
        /**
         * @brief get proposal number of current proposal.
@@ -110,13 +114,28 @@ struct proposal_substructure_s {
        u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
 
        /**
+        * @brief get the number of transforms in current proposal.
+        * 
+        * @param this          calling proposal_substructure_t object
+        * @return                      transform count in current proposal
+        */
+       size_t (*get_transform_count) (proposal_substructure_t *this);
+
+       /**
+        * @brief get size of the set spi in bytes.
+        * 
+        * @param this          calling proposal_substructure_t object
+        * @return                      size of the spi in bytes
+        */
+       size_t (*get_spi_size) (proposal_substructure_t *this);
+
+       /**
         * @brief Sets the protocol id of current proposal.
         *
         * @param this          calling proposal_substructure_t object
         * @param id                    protocol id to set
-        * @return                      - SUCCESS
         */
-       status_t (*set_protocol_id) (proposal_substructure_t *this,u_int8_t protocol_id);
+       void (*set_protocol_id) (proposal_substructure_t *this,u_int8_t protocol_id);
        
        /**
         * @brief get protocol id of current proposal.
@@ -125,7 +144,31 @@ struct proposal_substructure_s {
         * @return                      protocol id of current proposal substructure.
         */
        u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
+       
+       /**
+        * @brief Get informations for a specific transform type. 
+        * 
+        * @param this                  calling proposal_substructure_t object
+        * @param type                  type to get informations for
+        * @param transform_id  transform id of the specific type
+        * @param key_length    key length of the specific key length transform attribute
+        * @return                      
+        *                                              - SUCCESS if transform type is part of this proposal and 
+        *                                               all data (incl. key length) could be fetched
+        *                                              - NOT_FOUND if transform type is not part of this proposal
+        */
+       status_t (*get_info_for_transform_type) (proposal_substructure_t *this,transform_type_t type, u_int16_t *transform_id, u_int16_t *key_length);
 
+       /**
+        * @brief Sets the next_payload field of this substructure
+        * 
+        * If this is the last proposal, next payload field is set to 0,
+        * otherwise to 2
+        *
+        * @param this          calling proposal_substructure_t object
+        * @param is_last       When TRUE, next payload field is set to 0, otherwise to 2
+        */
+       void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
 
        /**
         * @brief Returns the currently set SPI of this proposal.
@@ -144,41 +187,32 @@ struct proposal_substructure_s {
         * 
         * @param this  calling proposal_substructure_t object
         * @param spi   chunk_t pointing to the value to set
-        * @return              
-        *                              - SUCCESS or
-        *                              - OUT_OF_RES
         */
-       status_t (*set_spi) (proposal_substructure_t *this, chunk_t spi);
+       void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
 
        /**
         * @brief Clones an proposal_substructure_t object.
         *
         * @param this  proposal_substructure_t object to clone
-        * @param clone cloned object will be written there
-        * @return              
-        *                              - SUCCESS
-        *                              - OUT_OF_RES
+        * @return              cloned object
         */
-       status_t (*clone) (proposal_substructure_t *this,proposal_substructure_t **clone);
+       proposal_substructure_t* (*clone) (proposal_substructure_t *this);
 
        /**
         * @brief Destroys an proposal_substructure_t object.
         *
         * @param this  proposal_substructure_t object to destroy
-        * @return              
-        *                              SUCCESS in any case
         */
-       status_t (*destroy) (proposal_substructure_t *this);
+       void (*destroy) (proposal_substructure_t *this);
 };
 
 /**
  * @brief Creates an empty proposal_substructure_t object
  * 
- * @return                     
- *                                     - created proposal_substructure_t object, or
- *                                     - NULL if failed
+ * @return                     created proposal_substructure_t object
+ * 
+ * @ingroup payloads
  */
 proposal_substructure_t *proposal_substructure_create();