Use struct containing the parameters for Create function
[strongswan.git] / src / libpts / tcg / tcg_pts_attr_simple_comp_evid.c
index 95a83c6..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,16 +410,16 @@ METHOD(pa_tnc_attr_t, destroy, void,
        free(this);
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_flags, pts_attr_simple_comp_evid_flag_t,
+METHOD(tcg_pts_attr_simple_comp_evid_t, is_pcr_info_included, bool,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
-       return this->flags;
+       return this->pcr_info_included;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_flags, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, pts_attr_simple_comp_evid_flag_t flags)
+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)
 {
-       this->flags = flags;
+       return this->flags;
 }
 
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_sub_component_depth, u_int32_t,
@@ -450,25 +446,12 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_qualifier, pts_qualifier_t,
        return this->qualifier;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_qualifier, void,
-               private_tcg_pts_attr_simple_comp_evid_t *this,
-               pts_qualifier_t qualifier)
-{
-       this->qualifier = qualifier;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_funct_name, pts_funct_comp_name_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->name;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_comp_funct_name, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, pts_funct_comp_name_t name)
-{
-       this->name = name;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_measurement_type, u_int8_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
@@ -481,85 +464,42 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_extended_pcr, u_int32_t,
        return this->extended_pcr;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_extended_pcr, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, u_int32_t extended_pcr)
-{
-       this->extended_pcr = extended_pcr;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_hash_algorithm, pts_meas_algorithms_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->hash_algorithm;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_hash_algorithm, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this,
-       pts_meas_algorithms_t hash_algorithm)
-{
-       this->hash_algorithm = hash_algorithm;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_trans, pts_pcr_transform_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->transformation;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_trans, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, pts_pcr_transform_t transformation)
-{
-       this->transformation = transformation;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_measurement_time, chunk_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->measurement_time;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_measurement_time, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t measurement_time)
-{
-       this->measurement_time = measurement_time;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_policy_uri, chunk_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->policy_uri;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_policy_uri, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t policy_uri)
-{
-       this->policy_uri = policy_uri;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_before_value, chunk_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->pcr_before;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_before_value, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t pcr_before)
-{
-       this->pcr_before = pcr_before;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_after_value, chunk_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->pcr_after;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_after_value, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t pcr_after)
-{
-       this->pcr_after = pcr_after;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_len, u_int16_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
@@ -578,30 +518,13 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_measurement, chunk_t,
        return this->measurement;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_comp_measurement, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t measurement)
-{
-       this->measurement = measurement;
-}
-
 /**
  * Described in header.
  */
-pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(
-                                                                       pts_attr_simple_comp_evid_flag_t flags,
-                                                                       u_int32_t depth, u_int32_t vendor_id,
-                                                                       pts_qualifier_t qualifier,
-                                                                       pts_funct_comp_name_t name,
-                                                                       u_int32_t extended_pcr,
-                                                                       pts_meas_algorithms_t hash_algorithm,
-                                                                       pts_pcr_transform_t transformation,
-                                                                       chunk_t measurement_time,
-                                                                       chunk_t policy_uri,
-                                                                       chunk_t pcr_before, chunk_t pcr_after,
-                                                                       chunk_t measurement)
+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;
-
+       
        INIT(this,
                .public = {
                        .pa_tnc_attribute = {
@@ -614,50 +537,40 @@ 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,
-                       .set_flags= _set_flags,
                        .get_sub_component_depth = _get_sub_component_depth,
                        .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id,
                        .get_family = _get_family,
                        .get_qualifier = _get_qualifier,
-                       .set_qualifier = _set_qualifier,
                        .get_comp_funct_name = _get_comp_funct_name,
-                       .set_comp_funct_name = _set_comp_funct_name,
                        .get_measurement_type = _get_measurement_type,
                        .get_extended_pcr = _get_extended_pcr,
-                       .set_extended_pcr = _set_extended_pcr,
                        .get_hash_algorithm = _get_hash_algorithm,
-                       .set_hash_algorithm = _set_hash_algorithm,
                        .get_pcr_trans = _get_pcr_trans,
-                       .set_pcr_trans = _set_pcr_trans,
                        .get_measurement_time = _get_measurement_time,
-                       .set_measurement_time = _set_measurement_time,
                        .get_policy_uri = _get_policy_uri,
-                       .set_policy_uri = _set_policy_uri,
                        .get_pcr_before_value = _get_pcr_before_value,
-                       .set_pcr_before_value = _set_pcr_before_value,
                        .get_pcr_after_value = _get_pcr_after_value,
-                       .set_pcr_after_value = _set_pcr_after_value,
                        .get_pcr_len = _get_pcr_len,
                        .get_comp_measurement = _get_comp_measurement,
-                       .set_comp_measurement = _set_comp_measurement,
                },
                .vendor_id = PEN_TCG,
                .type = TCG_PTS_SIMPLE_COMP_EVID,
-               .flags = flags,
-               .depth = depth,
-               .comp_vendor_id = vendor_id,
+               .flags = params.flags,
+               .depth = params.depth,
+               .comp_vendor_id = params.vendor_id,
                .family = PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM,
-               .qualifier = qualifier,
-               .name = name,
-               .extended_pcr = extended_pcr,
-               .hash_algorithm = hash_algorithm,
-               .transformation = transformation,
-               .measurement_time = measurement_time,
-               .policy_uri = policy_uri,
-               .pcr_before = pcr_before,
-               .pcr_after = pcr_after,
-               .measurement = measurement,
+               .qualifier = params.qualifier,
+               .name = params.name,
+               .extended_pcr = params.extended_pcr,
+               .hash_algorithm = params.hash_algorithm,
+               .transformation = params.transformation,
+               .measurement_time = params.measurement_time,
+               .policy_uri = chunk_clone(params.policy_uri),
+               .pcr_before = params.pcr_before,
+               .pcr_after = params.pcr_after,
+               .measurement = chunk_clone(params.measurement),
        );
 
        return &this->public.pa_tnc_attribute;
@@ -683,36 +596,27 @@ 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,
-                       .set_flags= _set_flags,
                        .get_sub_component_depth = _get_sub_component_depth,
                        .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id,
                        .get_family = _get_family,
                        .get_qualifier = _get_qualifier,
-                       .set_qualifier = _set_qualifier,
                        .get_comp_funct_name = _get_comp_funct_name,
-                       .set_comp_funct_name = _set_comp_funct_name,
                        .get_measurement_type = _get_measurement_type,
                        .get_extended_pcr = _get_extended_pcr,
-                       .set_extended_pcr = _set_extended_pcr,
                        .get_hash_algorithm = _get_hash_algorithm,
-                       .set_hash_algorithm = _set_hash_algorithm,
                        .get_pcr_trans = _get_pcr_trans,
-                       .set_pcr_trans = _set_pcr_trans,
                        .get_measurement_time = _get_measurement_time,
-                       .set_measurement_time = _set_measurement_time,
                        .get_policy_uri = _get_policy_uri,
-                       .set_policy_uri = _set_policy_uri,
                        .get_pcr_before_value = _get_pcr_before_value,
-                       .set_pcr_before_value = _set_pcr_before_value,
                        .get_pcr_after_value = _get_pcr_after_value,
-                       .set_pcr_after_value = _set_pcr_after_value,
                        .get_pcr_len = _get_pcr_len,
                        .get_comp_measurement = _get_comp_measurement,
-                       .set_comp_measurement = _set_comp_measurement,
                },
                .vendor_id = PEN_TCG,
                .type = TCG_PTS_SIMPLE_COMP_EVID,
+               .family = PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM,
                .value = chunk_clone(data),
        );