Use struct containing the parameters for Create function
[strongswan.git] / src / libpts / tcg / tcg_pts_attr_simple_comp_evid.c
index 69ff00d..b2798d0 100644 (file)
@@ -131,6 +131,11 @@ struct private_tcg_pts_attr_simple_comp_evid_t {
        pts_attr_simple_comp_evid_flag_t flags;
 
        /**
+        * PCR Information included
+        */
+       bool pcr_info_included;
+
+       /**
         * Sub-component Depth
         */
        u_int32_t depth;
@@ -153,7 +158,7 @@ struct private_tcg_pts_attr_simple_comp_evid_t {
        /**
         * Component Functional Name
         */
-       pts_funct_comp_name_t name;
+       pts_ita_funct_comp_name_t name;
        
        /**
         * Measurement type
@@ -288,8 +293,11 @@ METHOD(pa_tnc_attr_t, build, void,
                writer->write_data  (writer, this->pcr_before);
                writer->write_data  (writer, this->pcr_after);
        }
-       
-       writer->write_data (writer, this->measurement);
+
+       if (this->measurement.ptr && this->measurement.len > 0)
+       {
+               writer->write_data (writer, this->measurement);
+       }
        
        this->value = chunk_clone(writer->get_buf(writer));
        writer->destroy(writer);
@@ -330,13 +338,6 @@ METHOD(pa_tnc_attr_t, process, status_t,
                this->family += 2;
        }
        
-       /* TODO: Generate an IF-M error attribute indicating */
-       /* TCG_PTS_INVALID_NAME_FAM */
-       //if (&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
-       //{
-       //      DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
-       //}
-       
        if (((fam_and_qualifier >> 5) & 1) )
        {
                this->qualifier.kernel = true;
@@ -346,7 +347,6 @@ METHOD(pa_tnc_attr_t, process, status_t,
                this->qualifier.sub_component = true;
        }
        this->qualifier.type = ( fam_and_qualifier & 0xF );
-       /* TODO: Check the type is defined in pts_attr_req_funct_comp_type_t */
 
        /* Unknown or Wildcard should not be used for Qualification*/
        if (!(fam_and_qualifier & 0x3F) || (fam_and_qualifier & 0x3F) == 0x3F)
@@ -356,8 +356,6 @@ METHOD(pa_tnc_attr_t, process, status_t,
        }
        
        reader->read_uint32(reader, &this->name);
-       /* TODO: Check the name is defined in pts_funct_comp_name_t */
-       
        reader->read_uint8(reader, &measurement_type);
        this->measurement_type = (measurement_type >> 7 ) & 1;
        
@@ -367,15 +365,14 @@ METHOD(pa_tnc_attr_t, process, status_t,
        
        reader->read_uint8(reader, &transformation);
        this->transformation = transformation;
-       /* TODO: Check the transformation is defined in pts_pcr_transform_t */
        
        reader->read_data(reader, PTS_SIMPLE_COMP_EVID_MEASUREMENT_TIME_SIZE,
                          &this->measurement_time);
        this->measurement_time = chunk_clone(this->measurement_time);
-       
+
        /*  Optional Policy URI field is included */
-       if (this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL ||
-               this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS)
+       if ((this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL) ||
+               (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS))
        {
                u_int16_t policy_uri_len;
                reader->read_uint16(reader, &policy_uri_len);
@@ -384,7 +381,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
        }
        
        /*  Optional PCR value fields are included */
-       if (this->flags & PTS_SIMPLE_COMP_EVID_FLAG_PCR)
+       if (this->pcr_info_included)
        {
                u_int16_t pcr_value_len;
                reader->read_uint16(reader, &pcr_value_len);
@@ -393,7 +390,6 @@ METHOD(pa_tnc_attr_t, process, status_t,
                reader->read_data(reader, pcr_value_len, &this->pcr_after);
                this->pcr_after = chunk_clone(this->pcr_after);
        }
-       
        measurement_len = reader->remaining(reader);
        reader->read_data(reader, measurement_len, &this->measurement);
        this->measurement = chunk_clone(this->measurement);
@@ -414,6 +410,12 @@ METHOD(pa_tnc_attr_t, destroy, void,
        free(this);
 }
 
+METHOD(tcg_pts_attr_simple_comp_evid_t, is_pcr_info_included, bool,
+       private_tcg_pts_attr_simple_comp_evid_t *this)
+{
+       return this->pcr_info_included;
+}
+
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_flags, pts_attr_simple_comp_evid_flag_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
@@ -519,8 +521,7 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_measurement, chunk_t,
 /**
  * Described in header.
  */
-pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(
-                                                                       tcg_pts_attr_simple_comp_evid_params_t params)
+pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(tcg_pts_attr_simple_comp_evid_params_t params)
 {
        private_tcg_pts_attr_simple_comp_evid_t *this;
        
@@ -536,6 +537,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(
                                .process = _process,
                                .destroy = _destroy,
                        },
+                       .is_pcr_info_included = _is_pcr_info_included,
                        .get_flags= _get_flags,
                        .get_sub_component_depth = _get_sub_component_depth,
                        .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id,
@@ -565,10 +567,10 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(
                .hash_algorithm = params.hash_algorithm,
                .transformation = params.transformation,
                .measurement_time = params.measurement_time,
-               .policy_uri = params.policy_uri,
+               .policy_uri = chunk_clone(params.policy_uri),
                .pcr_before = params.pcr_before,
                .pcr_after = params.pcr_after,
-               .measurement = params.measurement,
+               .measurement = chunk_clone(params.measurement),
        );
 
        return &this->public.pa_tnc_attribute;
@@ -594,6 +596,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create_from_data(chunk_t data)
                                .process = _process,
                                .destroy = _destroy,
                        },
+                       .is_pcr_info_included = _is_pcr_info_included,
                        .get_flags= _get_flags,
                        .get_sub_component_depth = _get_sub_component_depth,
                        .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id,